AES encryption in java / decrypt in C# -
i'm using below code encrypt email address using own key in java:
byte[] key = "testkeymaster123".getbytes("utf-8"); secretkeyspec _secretkey = new secretkeyspec(key, "aes"); string input = "some.email.m@gmail.com"; cipher cipher = cipher.getinstance("aes"); byte[] bytes = input.getbytes("utf-8"); cipher.init(cipher.encrypt_mode, _secretkey); byte[] output = cipher.dofinal(bytes); result = base64.encodetostring(output, base64.default);
and result is:
9�Ѹ��m�g���m�`7<z��je�g�l
and encoded result is:
i8pwv9ev5n5l0f5w/pzarrc7g8hjiac8v/lefv0vaeq=
and in c# i'm using below code decrypt it:
var text = "i8pwv9ev5n5l0f5w/pzarrc7g8hjiac8v/lefv0vaeq="; text = util.decodebase64(text); rijndaelmanaged rijndaelcipher = new rijndaelmanaged(); rijndaelcipher.mode = ciphermode.ecb; rijndaelcipher.padding = paddingmode.none; rijndaelcipher.keysize = 128; rijndaelcipher.blocksize = 128; byte[] encrypteddata = hextobytes(text); byte[] pwdbytes = key; byte[] keybytes = new byte[0x10]; int len = pwdbytes.length; if (len > keybytes.length) { len = keybytes.length; } array.copy(pwdbytes, keybytes, len); rijndaelcipher.key = keybytes; rijndaelcipher.iv = keybytes; byte[] plaintext = rijndaelcipher.createdecryptor().transformfinalblock(encrypteddata, 0, encrypteddata.length); var str = encoding.utf8.getstring(plaintext);
but decoded result is:
���w���k�^p��z�;�i!����^~�i�
which looks different java , decrypted result not email, it's become this:
,���m d�������
i'm newbie in field of encryption/decryption, , of above code gathered here , there. understood of code went through don't know what's wrong here. appreciated.
Comments
Post a Comment