sm2_encrypt_hex | R Documentation |
For ease of use, we have provided functions to encrypt data into hex or base64 format and decrypt them from these formats.
sm2_encrypt_hex(data, public_key)
sm2_decrypt_hex(data, private_key)
sm2_encrypt_base64(data, public_key)
sm2_decrypt_base64(data, private_key)
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 |
returns a hex string of the cipher text
returns a raw vector of the plain text
returns a base64 string of the cipher text
returns a raw vector of the plain text
## 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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.