sm2_encrypt_hex {smcryptoR} | R Documentation |
SM2 Encrypt/Decrypt - hex and base64
Description
For ease of use, we have provided functions to encrypt data into hex or base64 format and decrypt them from these formats.
Usage
sm2_encrypt_hex(data, public_key)
sm2_decrypt_hex(data, private_key)
sm2_encrypt_base64(data, public_key)
sm2_decrypt_base64(data, private_key)
Arguments
data |
for encrypt, data is a raw vector, for decrypt, data is a hex or base64 string |
public_key |
a public key represented as a hexadecimal string |
private_key |
a private key represented as a hexadecimal string |
Value
- sm2_encrypt_hex
returns a hex string of the cipher text
- sm2_decrypt_hex
returns a raw vector of the plain text
- sm2_encrypt_base64
returns a base64 string of the cipher text
- sm2_decrypt_base64
returns a raw vector of the plain text
Examples
## encrypt and decrypt from hex string
keypair <- sm2_gen_keypair()
private_key <- keypair$private_key
public_key <- keypair$public_key
data <- 'abc' |> charToRaw()
enc <- sm2_encrypt_hex(data, public_key)
enc
dec <- sm2_decrypt_hex(enc, private_key)
dec
enc <- sm2_encrypt_base64(data, public_key)
enc
dec <- sm2_decrypt_base64(enc, private_key)
dec
[Package smcryptoR version 0.1.2 Index]