Skip to main content

Encryption

πŸ§©πŸ”’ Encryption/Decryption Implementation​

Encryption/Decryption implementation for reference (C# code):

string strFormattedString = string.Empty;
RijndaelManaged objAESEncDec = new RijndaelManaged();
objAESEncDec.Mode = CipherMode.CBC;
objAESEncDec.Padding = PaddingMode.PKCS7;
objAESEncDec.KeySize = 0x80;
objAESEncDec.BlockSize = 0x80;
byte[] bPwdBytes = Encoding.UTF8.GetBytes(strKey);

byte[] bKeyBytes = new byte[0x10];
int iPwdLen = bPwdBytes.Length;
if (iPwdLen > bKeyBytes.Length)
iPwdLen = bKeyBytes.Length;
Array.Copy(bPwdBytes, bKeyBytes, iPwdLen);
objAESEncDec.Key = bKeyBytes;
objAESEncDec.IV = bKeyBytes;

πŸ” For Encryption​

ICryptoTransform objTransform = objAESEncDec.CreateEncryptor(); byte[] bPlainText = Encoding.UTF8.GetBytes(strData); strFormattedString = Convert.ToBase64String(objTransform.TransformFinalBlock(bPlainText, 0, bPlainText.Length));

πŸ”“ For Decryption​

byte[] bEncryptedData = Convert.FromBase64String(strData); byte[] bPlainText = objAESEncDec.CreateDecryptor().TransformFinalBlock(bEncryptedData, 0, bEncryptedData.Length); strFormattedString = Encoding.UTF8.GetString(bPlainText);

πŸ—‚οΈ Note :

In the above implementation logic, β€œstrData” is the string value that needs to encrypt/decrypt. β€œstrKey” will be the Encryption key configured by Broker for each of the SSO links in WebAdmin.