sm2_sign | R Documentation |
SM2 is an asymmetric encryption algorithm, so it can be used to sign and verify signatures of data. The purpose of doing this is to ensure the integrity of the data and guarantee its authenticity. Typically, the data owner uses the SM3 message digest algorithm to calculate the hash value and signs it with the private key, generating signed data. Then the owner distributes the original data and the signed data of the original data to the receiver. The receiver uses the public key and the received signed data to perform the verification operation. If the verification is successful, it is considered that the received original data has not been tampered with.
sm2_sign(id, data, private_key)
sm2_verify(id, data, sign, public_key)
sm2_sign_to_file(id, data, sign_file, private_key)
sm2_verify_from_file(id, data, sign_file, public_key)
id |
the signer's id, must be a raw vector |
data |
orignal data, must be a raw vector |
private_key |
a private key represented as a hexadecimal string |
sign |
sign data of the original data or file |
public_key |
a public key represented as a hexadecimal string |
sign_file |
file path of the sign data to load |
returns a raw vector contains the signature
returns 1 if verified, 0 if not verified
returns nothing, and a signature file will be saved in the specified path
returns 1 if verified, 0 if not verified
## sign and verify
id <- charToRaw('yumeng@company.com')
data <- charToRaw('abc')
keypair <- sm2_gen_keypair()
private_key <- keypair$private_key
public_key <- keypair$public_key
sign_data <- sm2_sign(id, data, private_key)
verify_result <- sm2_verify(id, data, sign_data, public_key)
## Not run:
sm2_sign_to_file(id, data, 'sign_data.sig', private_key)
sm2_verify_from_file(id, data, 'sign_data.sig', public_key)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.