sm2_gen_keypair {smcryptoR} | R Documentation |
SM2 Key Pair
Description
In the SM2 encryption algorithm, the private key and public key appear in pairs. The private key is a 64-bit hexadecimal string, and the public key is a 128-bit hexadecimal string, excluding the "04" prefix at the beginning. The public key is included in the private key and can be derived from the private key. We use the public key for encryption, the private key for decryption, the private key for signing, and the public key for verification.
Usage
sm2_gen_keypair()
sm2_pk_from_sk(private_key)
sm2_privkey_valid(private_key)
sm2_pubkey_valid(public_key)
sm2_keypair_from_pem_file(pem_file)
sm2_keypair_to_pem_file(private_key, pem_file)
sm2_pubkey_from_pem_file(pem_file)
sm2_pubkey_to_pem_file(public_key, pem_file)
Arguments
private_key |
a private key represented as a hexadecimal string |
public_key |
a public key represented as a hexadecimal string |
pem_file |
local pem file path |
Details
- sm2_gen_keypair
generate a ramdom key pair
- sm2_pk_from_sk
export public key from a private key
- sm2_privkey_valid
check whether a private key is legal
- sm2_pubkey_valid
check whether a public key is legal
- sm2_keypair_from_pem_file
import private key from a local pem file
- sm2_keypair_to_pem_file
save a private key to a local pem file
- sm2_pubkey_from_pem_file
import public key from a local pem file
- sm2_pubkey_to_pem_file
save a public key to a local pem file
Value
- sm2_gen_keypair
returns a list contains a random private key and the corresponding public key
- sm2_pk_from_sk
returns a character string, the public key exported from a private key
- sm2_privkey_valid
returns 1 if valid, 0 if invalid
- sm2_pubkey_valid
returns 1 if valid, 0 if invalid
- sm2_keypair_from_pem_file
returns a list contains a random private key and the corresponding public key
- sm2_keypair_to_pem_file
returns nothing, and a local file contains the keypair will be saved in the specified path
- sm2_pubkey_from_pem_file
returns a character string, the public key saved in the local file
- sm2_pubkey_to_pem_file
returns nothing, and a local file contains the public key will be saved in the specified path
Examples
## generate a ramdom keypair
keypair <- sm2_gen_keypair()
keypair$private_key
keypair$public_key
## export public key from private key
sm2_pk_from_sk(keypair$private_key)
## check whether the private key is legal
sm2_privkey_valid(keypair$private_key)
## check whether the public key is legal
sm2_pubkey_valid(keypair$public_key)
## Not run:
sm2_keypair_to_pem_file(keypair, 'keypair.pem')
sm2_keypair_from_pem_file('keypair.pem')
sm2_pubkey_to_pem_file(keypair$public_key, 'pubkey.pem')
sm2_pubkey_from_pem_file('pubkey.pem')
## End(Not run)