How to encrypt JSON object

Java code for all API methods

public String encryptKRSCertificate(String encodedJsonObj, String encodedAESKey) throws Exception
{
byte[] decodedKey = Base64.decode(encodedAESKey;
SecretKey key = new SecretKeySpec(decodedKey, 0, decodedKey.length, "AES"); byte[] iv = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
IvParameterSpec ivspec = new IvParameterSpec(iv);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");


cipher.init(1, key, ivspec);
byte[] encrypted = cipher.doFinal(Base64.decode(orignalCertificate)); String encryptedKeystore = new String(Base64.encode(encrypted)); return encryptedKeystore;
}

encodedAESKey

M

String

You need to pass BASE 64 encoded AES key. AES key will be shared with you by us after registration.

encodedJsonObj

M

String

You need to pass BASE 64 encoded JSON Object. JSON object is an output of section 5.

.NET code for all API methods

public byte[] EncryptDataAES(byte[] toEncrypt, string encodedAESKey)
{
byte[] key = Convert.FromBase64String(encodedAESKey); IBufferedCipher cipher =
CipherUtilities.GetCipher("AES/CBC/PKCS5PADDING"); cipher.Init(true, new KeyParameter(key));
int outputSize = cipher.GetOutputSize(toEncrypt.Length); byte[] tempOP = new byte[outputSize];
int processLen = cipher.ProcessBytes(toEncrypt, 0, toEncrypt.Length, tempOP, 0);
int outputLen = cipher.DoFinal(tempOP, processLen); byte[] result = new byte[processLen + outputLen]; System.Array.Copy(tempOP, 0, result, 0, result.Length); return result;
}

encodedAESKey

M

String

You need to pass BASE 64 encoded AES key. AES key will be shared with you by us after registration.

toEncrypt

M

Byte

You need to pass JSON Object. JSON object is an output of section 5.

Last updated