rsa()

Description:

Perform RSA asymmetric encryption.

Syntax:

rsa(input,m)

 

rsa(input,mod:e)

Use random modulus/exponent keys to encrypt.

Note:

The function uses RSA asymmetric encryption algorithm to encrypt/decrypt parameter input. The public key is for encryption, and the private is for decryption.

Parameter:

input

Data to be encrypted/decrypted; Usually parameter input is BLOB type; also supports automatic string encoding.

m

Access key

e

Key exponent

mod

Key modulus

Option:

@d

Perform decryption; here parameter input is the ciphertext to be decrypted

@k

rsa@k(n) generates a key of length n and returns a sequence whose members are [public key m,private key m], where m is the BLOB type;

n is the length of the key, which should be equal to or greater than 512 and whose default value is 2048.

@km

rsa@km(n) generates random modulus/exponent keys and return a sequence whose members are [key modulus mod, public key exponent e, private key exponent e], where mod and e are string type

@bkm

rsa@bkm(n) generates random modulus/exponent keys and return a sequence whose members are [key modulus mod, public key exponent e, private key exponent e] where mod and e are BLOB type

Return value:

BLOB value/Sequence

Example:

 

A

 

1

Hello World!

 

2

=charencode(A1;"GBK")

Generate a BLOB value using A1’s string.

3

=rsa@k(512)

Generate a sequence made up of the key whose length is 512 and whose members are [public key, private key]:

4

=rsa(A2,A3(1))

Use the public key in A3 to encrypt A2’s content.

5

=rsa@d(A4,A3(2))

@d option works to decrypt A4’s content using the private key in A3.

6

=charencode(A5;"GBK")

Generate a string using A5’s BLOB value and return the result: Hello World!

Use random modulus/exponent key to encrypt and decrypt:

 

A

 

1

Hello World!

 

2

=rsa@km()

Use default value 2048 as parameter n is absent; @km options work to generate random modulus/exponent keys and return a sequence whose members are [key modulus, public key exponent, private key exponent]:

3

=rsa(A1,A2(1):A2(2))

Use the key modulus and public key exponent in A2 to encrypt A1’s content.

4

=rsa@d(A3,A2(1):A2(3))

@d option works to decrypt A3’s content using the key modulus and privage key exponent in A2.

5

=charencode(A4)

Generate a string using A4’s BLOB value – use character set utf-8 by default, and return the result: Hello World!