Encrypt a String Using an RSA Key
RSA being a stream cipher does not require IV. You do not need to send data to the NAE Server in chunks of any particular size. While encrypting data using RSA key, the key size and padding is taken into consideration.
To encrypt a string:
Create a NAE Session. Pass the NAE username, password, and property file path as arguments.
session = new NaeSession(user, pass, @"../../../../../../../CADP.NETCore_Properties.xml");
Create instance of the key that will be used for encryption.
NaeKeyManagement nkm = new NaeKeyManagement(session); key = (NaeRsaKey)nkm.GetKey("generic_rsa_key");
Note
The
generic_rsa_key
must be present on the server.Call the
Encrypt
method of the key and pass the data you want to encrypt.RSAEncryptionPadding padding = RSAEncryptionPadding.OaepSHA256; byte[] encrBytes = key.Encrypt(inputBytes, padding);