0% found this document useful (0 votes)
7 views2 pages

6

The document provides C#.Net code snippets for symmetric encryption and decryption using AES. It includes methods for decrypting an encrypted SEK received during authentication and for encrypting data using the decrypted SEK. The code demonstrates handling of byte arrays and error management during the encryption and decryption processes.

Uploaded by

avrajput0141
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

6

The document provides C#.Net code snippets for symmetric encryption and decryption using AES. It includes methods for decrypting an encrypted SEK received during authentication and for encrypting data using the decrypted SEK. The code demonstrates handling of byte arrays and error management during the encryption and decryption processes.

Uploaded by

avrajput0141
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

public string InfCd { get; set; }

public List<Infodata> Desc { get; set; }


}
public class Infodata
{
public string ErrorCode { get; set; }
public string ErrorMessage { get; set; }
}
public data Data { get; set; }
public class data
{
public string ClientId { get; set; }
public string UserName { get; set; }
public string AuthToken { get; set; }
public string Sek { get; set; }
public string TokenExpiry { get; set; }
public static implicit operator data(string v)
{
throw new NotImplementedException();
}
}
}
}

Symmetric Decryption (AES)

The following C#.Net code snippet can be used for decrypting the encrypted sek
using the appkey.

Here the encryptedSek is the one that is received in response to the


authentication.

public static byte[] DecryptBySymmetricKey(string encryptedSek, byte[]


appkey)
{
//Decrypting SEK
try
{
byte[] dataToDecrypt = Convert.FromBase64String(encryptedSek);
var keyBytes = appkey;
AesManaged tdes = new AesManaged();
tdes.KeySize = 256;
tdes.BlockSize = 128;
tdes.Key = keyBytes;
tdes.Mode = CipherMode.ECB;
tdes.Padding = PaddingMode.PKCS7;
ICryptoTransform decrypt__1 = tdes.CreateDecryptor();
byte[] deCipher = decrypt__1.TransformFinalBlock(dataToDecrypt, 0,
dataToDecrypt.Length);
tdes.Clear();
string EK_result = Convert.ToBase64String(deCipher);
return EK_result;
}
catch (Exception ex)
{
throw ex;
}
}

Symmetric Key Encryption (AES)

The following C#.Net code snippet can be used for encrypting the data using the
symmetric key.

The decrypted sek need to be passed here.(It is got by decrypting the obtained SEK
after successful authentication)

public static string EncryptBySymmetricKey(string jsondata, string sek)


{
//Encrypting SEK
try
{
byte[] dataToEncrypt = Convert.FromBase64String(jsondata);
var keyBytes = Convert.FromBase6

You might also like