Learn R Programming

smcryptoR (version 0.1.2)

sm2_encrypt_to_file: SM2 Encrypt/Decrypt - file

Description

For ease of use, we have provided functions to encrypt or decrypt data directly from files.

Usage

sm2_encrypt_to_file(data, enc_file, public_key)

sm2_decrypt_from_file(dec_file, private_key)

Value

sm2_encrypt_to_file

returns nothing, an encrypted file will be saved in the specified path

sm2_decrypt_from_file

returns nothing, a decrypted file will be saved in the specified path

Arguments

data

data to be encrypted, must be a raw vector

enc_file

the enctypted file to be saved

public_key

a public key represented as a hexadecimal string

dec_file

the encrypted file to be loaded

private_key

a private key represented as a hexadecimal string

Examples

Run this code
## encrypt and decrypt from file
if (FALSE) {
  data <- 'abc' |> charToRaw()
  keypair <- sm2_gen_keypair()
  private_key <- keypair$private_key
  public_key <- keypair$public_key
  sm2_encrypt_to_file(data, 'data.enc', public_key)
  sm2_decrypt_from_file('data.enc', private_key)
}

Run the code above in your browser using DataLab