In order to pass data between our server and yours we use the Advanced Encryption Standard (AES 256), which is a symmetric encryption algorithm and one of the most secure currently available.
For example, to retrieve the PIN, you must retrieve the encrypted pin data by using the ViewPin API method. After receiving the data, the data is decrypted using AES256 algorithm with the appropriate IV and secret key.
Note: You receive the Encryption/Decryption keys in the response of the Login method as a Security key parameter.
Contis will pass information such as a virtual payment card CVV (security code) in encrypted format. Any encrypted information can be decrypted using a unique key provided to you by Contis.
Encrypt the data
To encrypt the data, use the AES256 algorithm. The C# code (shown below) helps you to encrypt the data. This function is used to encrypt data using the Security Key.
C# code
publicbyte[] FromHexString(String hex)
{
byte[] bts = newbyte[hex.Length / 2];
for (int i = 0; i < bts.Length; i++)
{
bts[i] = (byte)Convert.ToInt32(hex.Substring(2 * i, 2), 16);
}
return bts;
}
publicstringEncrypt(string PlainValue, string securityKey)
{
byte[] iv = FromHexString(securityKey.Remove(32, 64));
byte[] key = FromHexString(securityKey.Remove(0, 32));
returnAES256Encrypt(PlainValue, key, iv);
}
publicstringAES256Encrypt(string clearText, byte[] key, byte[] iv)
{
try
{
AesCryptoServiceProvider aesCipher = new AesCryptoServiceProvider();
byte[] plainText = System.Text.Encoding.Unicode.GetBytes(clearText);
ICryptoTransform encryptor = aesCipher.CreateEncryptor(key, iv);
using (MemoryStream msEncrypt = new MemoryStream())
{
//Defines a stream that links data streams to cryptographic transformations using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
{
csEncrypt.Write(plainText, 0, plainText.Length);
//Writes the final state and clears the buffer
csEncrypt.FlushFinalBlock();
byte[] cipherBytes = msEncrypt.ToArray();
string encryptedData = Convert.ToBase64String(cipherBytes);
return encryptedData;
}
}
}
catch (Exception)
{
returnstring.Empty;
}
}
PlainCard: 4763580507487320
SecurityKey: e9de8858a76c406eb2cdde4a33f6e1b286ee3efccfb94506a7dfcfd04e9720bc46634d7679db40b1afa94cfe2d2f2018
IV: e9de8858a76c406eb2cdde4a33f6e1b2
(First 32 character of security key)
KEY: 86ee3efccfb94506a7dfcfd04e9720bc46634d7679db40b1afa94cfe2d2f2018
(Last 64 character of security key)
ENCRYPTED value: c6T1M9hIAKr1K0qGCo7Ft5L4VupBuTbtYdhZ8zXHwAmzF2vREyDyMW/SzhHts0pA
Note: Use the CBC mode of the AES256 encryption and UTF-16 (Unicode) as the encoding.
Decrypt the data
To decrypt the data, use the AES256 algorithm. The C# code (shown below) helps you to decrypt the data.
This function is used to decrypt data using the Security Key
publicbyte[] FromHexString(String hex)
{
byte[] bts = newbyte[hex.Length / 2];
for (int i = 0; i < bts.Length; i++)
{
bts[i] = (byte)Convert.ToInt32(hex.Substring(2 * i, 2), 16);
}
return bts;
}
publicstringDecrypt(string PlainValue, string securityKey)
{
byte[] iv = FromHexString(securityKey.Remove(32, 64));
byte[] key = FromHexString(securityKey.Remove(0, 32));
returnAES256Decrypt(PlainValue, key, iv);
}
publicstringAES256Decrypt(string encrpytedText, byte[] key, byte[] iv)
{
try
{
AesCryptoServiceProvider aesCipher = new AesCryptoServiceProvider();
byte[] encryptedData = Convert.FromBase64String(encrpytedText);
ICryptoTransform decryptor = aesCipher.CreateDecryptor(key, iv);
using (MemoryStream msDecrypt = new MemoryStream(encryptedData))
{
//Defines the cryptographic stream for decryption.The stream contains decrypted data using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
{
byte[] plainText = newbyte[encryptedData.Length];
int decryptedCount = csDecrypt.Read(plainText, 0, plainText.Length);
string decryptedData = Encoding.Unicode.GetString(plainText, 0, decryptedCount);
return decryptedData;
}
}
}
catch (Exception)
{
returnstring.Empty;
}
}