Has anybody implemented PBKDF2 based AES for symmetric encryption in Windows Phone 8 with a 256 bit key? If yes any help will be greatly appreciated. Is there any other class in WP8 other than System.Security.Cryptography.Rfc2898DeriveBytes which returns a 256 bit key for PBKDF2? A 32 bit key is weak and can be cracked. (C#) RSA Encrypt/Decrypt AES Key. Demonstrates how to use RSA to protect a key for AES encryption. It can be used in this scenario: You will provide your RSA public key to any number of counterparts. Your counterpart will generate an AES key, encrypt data (or a file) using it, then encrypt the AES key using your RSA public key.
#regionEncryption |
/// <summary> |
/// Generate a private key |
/// From : www.chapleau.info/blog/2011/01/06/usingsimplestringkeywithaes256encryptioninc.html |
/// </summary> |
privatestaticstringGenerateKey(intiKeySize) |
{ |
RijndaelManagedaesEncryption=newRijndaelManaged(); |
aesEncryption.KeySize=iKeySize; |
aesEncryption.BlockSize=128; |
aesEncryption.Mode=CipherMode.CBC; |
aesEncryption.Padding=PaddingMode.PKCS7; |
aesEncryption.GenerateIV(); |
stringivStr=Convert.ToBase64String(aesEncryption.IV); |
aesEncryption.GenerateKey(); |
stringkeyStr=Convert.ToBase64String(aesEncryption.Key); |
stringcompleteKey=ivStr+','+keyStr; |
returnConvert.ToBase64String(ASCIIEncoding.UTF8.GetBytes(completeKey)); |
} |
/// <summary> |
/// Encrypt |
/// From : www.chapleau.info/blog/2011/01/06/usingsimplestringkeywithaes256encryptioninc.html |
/// </summary> |
privatestaticstringEncrypt(stringiPlainStr, stringiCompleteEncodedKey, intiKeySize) |
{ |
RijndaelManagedaesEncryption=newRijndaelManaged(); |
aesEncryption.KeySize=iKeySize; |
aesEncryption.BlockSize=128; |
aesEncryption.Mode=CipherMode.CBC; |
aesEncryption.Padding=PaddingMode.PKCS7; |
aesEncryption.IV=Convert.FromBase64String(ASCIIEncoding.UTF8.GetString(Convert.FromBase64String(iCompleteEncodedKey)).Split(',')[0]); |
aesEncryption.Key=Convert.FromBase64String(ASCIIEncoding.UTF8.GetString(Convert.FromBase64String(iCompleteEncodedKey)).Split(',')[1]); |
byte[] plainText=ASCIIEncoding.UTF8.GetBytes(iPlainStr); |
ICryptoTransformcrypto=aesEncryption.CreateEncryptor(); |
byte[] cipherText=crypto.TransformFinalBlock(plainText, 0, plainText.Length); |
returnConvert.ToBase64String(cipherText); |
} |
/// <summary> |
/// Decrypt |
/// From : www.chapleau.info/blog/2011/01/06/usingsimplestringkeywithaes256encryptioninc.html |
/// </summary> |
privatestaticstringDecrypt(stringiEncryptedText, stringiCompleteEncodedKey, intiKeySize) |
{ |
RijndaelManagedaesEncryption=newRijndaelManaged(); |
aesEncryption.KeySize=iKeySize; |
aesEncryption.BlockSize=128; |
aesEncryption.Mode=CipherMode.CBC; |
aesEncryption.Padding=PaddingMode.PKCS7; |
aesEncryption.IV=Convert.FromBase64String(ASCIIEncoding.UTF8.GetString(Convert.FromBase64String(iCompleteEncodedKey)).Split(',')[0]); |
aesEncryption.Key=Convert.FromBase64String(ASCIIEncoding.UTF8.GetString(Convert.FromBase64String(iCompleteEncodedKey)).Split(',')[1]); |
ICryptoTransformdecrypto=aesEncryption.CreateDecryptor(); |
byte[] encryptedBytes=Convert.FromBase64CharArray(iEncryptedText.ToCharArray(), 0, iEncryptedText.Length); |
returnASCIIEncoding.UTF8.GetString(decrypto.TransformFinalBlock(encryptedBytes, 0, encryptedBytes.Length)); |
} |
#endregion |
hi fairly new to the cryptography.. Mediafire download key doesn't generate key. please suggest a resolution |