pub struct Sm2Key { /* private fields */ }Expand description
SM2 key pair (public + optional private key).
Implementations§
Source§impl Sm2Key
impl Sm2Key
Sourcepub fn generate() -> Result<Self, GmsslError>
pub fn generate() -> Result<Self, GmsslError>
Generate a new SM2 key pair.
Sourcepub fn from_encrypted_private_key_pem(
pem_data: &[u8],
password: &str,
) -> Result<Self, GmsslError>
pub fn from_encrypted_private_key_pem( pem_data: &[u8], password: &str, ) -> Result<Self, GmsslError>
Import from PKCS#8 encrypted private key PEM (in-memory).
Sourcepub fn to_encrypted_private_key_pem(
&self,
password: &str,
) -> Result<Vec<u8>, GmsslError>
pub fn to_encrypted_private_key_pem( &self, password: &str, ) -> Result<Vec<u8>, GmsslError>
Export to PKCS#8 encrypted private key PEM (in-memory).
Sourcepub fn from_public_key_pem(pem_data: &[u8]) -> Result<Self, GmsslError>
pub fn from_public_key_pem(pem_data: &[u8]) -> Result<Self, GmsslError>
Import from public key PEM (in-memory).
Sourcepub fn to_public_key_pem(&self) -> Result<Vec<u8>, GmsslError>
pub fn to_public_key_pem(&self) -> Result<Vec<u8>, GmsslError>
Export to public key PEM (in-memory).
Sourcepub fn from_private_key_pem(pem_data: &[u8]) -> Result<Self, GmsslError>
pub fn from_private_key_pem(pem_data: &[u8]) -> Result<Self, GmsslError>
Import from private key PEM (PKCS#8 PrivateKeyInfo, in-memory).
Sourcepub fn to_private_key_pem(&self) -> Result<Vec<u8>, GmsslError>
pub fn to_private_key_pem(&self) -> Result<Vec<u8>, GmsslError>
Export to private key PEM (PKCS#8 PrivateKeyInfo, in-memory).
Sourcepub fn from_public_key_der(der: &[u8]) -> Result<Self, GmsslError>
pub fn from_public_key_der(der: &[u8]) -> Result<Self, GmsslError>
Import from public key DER (SubjectPublicKeyInfo).
Sourcepub fn to_public_key_der(&self) -> Result<Vec<u8>, GmsslError>
pub fn to_public_key_der(&self) -> Result<Vec<u8>, GmsslError>
Export to public key DER (SubjectPublicKeyInfo).
Sourcepub fn from_private_key_der(der: &[u8]) -> Result<Self, GmsslError>
pub fn from_private_key_der(der: &[u8]) -> Result<Self, GmsslError>
Import from private key DER (PKCS#8 PrivateKeyInfo).
Sourcepub fn to_private_key_der(&self) -> Result<Vec<u8>, GmsslError>
pub fn to_private_key_der(&self) -> Result<Vec<u8>, GmsslError>
Export to private key DER (PKCS#8 PrivateKeyInfo).
Sourcepub fn from_public_key_pem_file(path: &str) -> Result<Self, GmsslError>
pub fn from_public_key_pem_file(path: &str) -> Result<Self, GmsslError>
Import from public key PEM file.
Sourcepub fn to_public_key_pem_file(&self, path: &str) -> Result<(), GmsslError>
pub fn to_public_key_pem_file(&self, path: &str) -> Result<(), GmsslError>
Export to public key PEM file.
Sourcepub fn from_encrypted_private_key_pem_file(
path: &str,
password: &str,
) -> Result<Self, GmsslError>
pub fn from_encrypted_private_key_pem_file( path: &str, password: &str, ) -> Result<Self, GmsslError>
Import from encrypted private key PEM file.
Sourcepub fn to_encrypted_private_key_pem_file(
&self,
path: &str,
password: &str,
) -> Result<(), GmsslError>
pub fn to_encrypted_private_key_pem_file( &self, path: &str, password: &str, ) -> Result<(), GmsslError>
Export to encrypted private key PEM file.
Sourcepub fn compute_z(&self, id: &str) -> Result<[u8; 32], GmsslError>
pub fn compute_z(&self, id: &str) -> Result<[u8; 32], GmsslError>
Compute the Z value (hash of signer identity + curve parameters + public key).
Sourcepub fn has_private_key(&self) -> bool
pub fn has_private_key(&self) -> bool
Returns true if this key has a private key.