How to create Aes 256bit Encryption with key in C# Windows Phone application? -
How to create Aes 256bit Encryption with key in C# Windows Phone application? -
i'm trying create aes 256bit encryption key in login screen. need big encrypted string i'm using 256bit result in little encrypted string.i have checked many samples windows desktop application not windows phone application. please help regarding this.
this code
namespace sampleencription { public partial class mainpage : phoneapplicationpage { public mainpage() { initializecomponent(); byte[] encryptedpassword; // create new instance of rijndaelmanaged // class. generates new key , initialization // vector (iv). using (var algorithm = new aesmanaged()) { algorithm.keysize = 256; algorithm.blocksize = 128; // encrypt string array of bytes. encryptedpassword = cryptology.encryptstringtobytes("password", algorithm.key, algorithm.iv); //string chars = encryptedpassword.aggregate(string.empty, (current, b) => current + b.tostring()); string chars = system.convert.tobase64string(encryptedpassword); debug.writeline(chars); } } } }
one class named cryptology:
namespace sampleencription { class cryptology { private const string salt = "603deb1015ca71be2b73aef0857d7781"; private const int sizeofbuffer = 1024 * 8; internal static byte[] encryptstringtobytes(string plaintext, byte[] key, byte[] iv) { // check arguments. if (plaintext == null || plaintext.length <= 0) { throw new argumentnullexception("plaintext"); } if (key == null || key.length <= 0) { throw new argumentnullexception("key"); } if (iv == null || iv.length <= 0) { throw new argumentnullexception("key"); } byte[] encrypted; // create rijndaelmanaged object // specified key , iv. using (var rijalg = new aesmanaged()) { rijalg.key = key; rijalg.iv = iv; // create decrytor perform stream transform. icryptotransform encryptor = rijalg.createencryptor(rijalg.key, rijalg.iv); // create streams used encryption. using (var msencrypt = new memorystream()) { using (var csencrypt = new cryptostream(msencrypt, encryptor, cryptostreammode.write)) { using (var swencrypt = new streamwriter(csencrypt)) { //write info stream. swencrypt.write(plaintext); } encrypted = msencrypt.toarray(); } } } // homecoming encrypted bytes memory stream. homecoming encrypted; } } }
instead of
string chars = system.convert.tobase64string(encryptedpassword);
do this
encoding.utf8.getstring(encryptedpassword, 0, encryptedpassword.length);
i think wp8 doesn't allow utilize system.text.encoding.default.getstring, can seek default utf8, assume cipher text in latin characters..
c# windows-phone-8 encryption aes
Comments
Post a Comment