/// <Summary> /// AES-256 encryption /// </Summary> /// <Param name = "toencrypt"> </param> /// <returns> </returns> Public String encrypt (string toencrypt) {// 256-aes key byte [] keyarray = utf8encoding. utf8.getbytes ("12345678901234567890123456789012"); byte [] toencryptarray = utf8encoding. utf8.getbytes (toencrypt); rijndaelmanaged rdel = new rijndaelmanaged (); rdel. key = keyarray; rdel. mode = ciphermode. ECB; rdel. padding = paddingmode. pkcs7; icryptotransform ctransform = rdel. createencryptor (); byte [] resultarray = ctransform. transformfinalblock (toencryptarray, 0, toencryptarray. length); Return convert. tobase64string (resultarray, 0, resultarray. length );} /// <summary> /// decrypt /// </Summary> /// <Param name = "todecrypt"> data to be decrypted </param> /// <returns> decrypted data </returns> Public String decrypt (string todecrypt) {// 256-aes key byte [] keyarray = utf8encoding. utf8.getbytes ("12345678901234567890123456789012"); byte [] toencryptarray = convert. frombase64string (todecrypt); rijndaelmanaged rdel = new rijndaelmanaged (); rdel. key = keyarray; rdel. mode = ciphermode. ECB; rdel. padding = paddingmode. pkcs7; icryptotransform ctransform = rdel. createdecryptor (); byte [] resultarray = ctransform. transformfinalblock (toencryptarray, 0, toencryptarray. length); Return utf8encoding. utf8.getstring (resultarray );}
AES-256 encryption and decryption