The key information is as follows.
Javascript
function Encrypt () {
var key = CryptoJS.enc.Utf8.parse (' 8080808080808080 ');
var IV = CryptoJS.enc.Utf8.parse (' 8080808080808080 ');
var Varin = document.getElementById ("Txtin"). Value;
var varout = CryptoJS.AES.encrypt (CryptoJS.enc.Utf8.parse (Varin), Key,
{
KEYSIZE:128/8,
Iv:iv,
Mode:CryptoJS.mode.CBC,
Padding:CryptoJS.pad.Pkcs7
});
document.getElementById ("Txtout"). Value = Varout;
}
function Decrypt () {
var key = CryptoJS.enc.Utf8.parse (' 8080808080808080 ');
var IV = CryptoJS.enc.Utf8.parse (' 8080808080808080 ');
var Varin = document.getElementById ("Txtout"). Value;
var varout = CryptoJS.AES.decrypt (Varin, Key,
{
KEYSIZE:128/8,
Iv:iv,
Mode:CryptoJS.mode.CBC,
Padding:CryptoJS.pad.Pkcs7
}). toString (CryptoJS.enc.Utf8);
document.getElementById ("Txtin"). Value = Varout;
}
C # (AES.cs)
Using System;
Using System.IO;
Using System.Security.Cryptography;
Using System.Text;
Namespace Aestest
{
public class AES
{
public static string Decryptstringaes (String ciphertext)
{
var keybytes = Encoding.UTF8.GetBytes ("8080808080808080");
var IV = Encoding.UTF8.GetBytes ("8080808080808080");
var encrypted = convert.frombase64string (ciphertext);
var decriptedfromjavascript = decryptstringfrombytes (encrypted, keybytes, IV);
return string. Format (Decriptedfromjavascript);
}
private static string Decryptstringfrombytes (byte[] ciphertext, byte[] key, byte[] IV)
{
Check arguments.
if (ciphertext = = NULL | | ciphertext.length <= 0)
{
throw new ArgumentNullException ("ciphertext");
}
if (key = = NULL | | key. Length <= 0)
{
throw new ArgumentNullException ("key");
}
if (iv = = NULL | | IV. Length <= 0)
{
throw new ArgumentNullException ("key");
}
Declare the string used to hold
The decrypted text.
string plaintext = null;
Create an RijndaelManaged object
With the specified key and Iv.
using (var rijalg = new RijndaelManaged ())
{
Settings
Rijalg.mode = CIPHERMODE.CBC;
rijalg.padding = PADDINGMODE.PKCS7;
rijalg.feedbacksize = 128;
Rijalg.key = Key;
RIJALG.IV = IV;
Create a decrytor to perform the stream transform.
var decryptor = Rijalg.createdecryptor (Rijalg.key, RIJALG.IV);
Try
{
Create the streams used for decryption.
using (var msdecrypt = new MemoryStream (ciphertext))
{
using (var csdecrypt = new CryptoStream (Msdecrypt, Decryptor, CryptoStreamMode.Read))
{
using (var srdecrypt = new StreamReader (csdecrypt))
{
Read the decrypted bytes from the decrypting stream
and place them in a string.
plaintext = Srdecrypt.readtoend ();
}
}
}
}
Catch
{
plaintext = "Keyerror";
}
}
return plaintext;
}
public static string Encryptstringaes (String ciphertext)
{
var keybytes = Encoding.UTF8.GetBytes ("8080808080808080"); Self-setting
var IV = Encoding.UTF8.GetBytes ("8080808080808080"); Self-setting
var encryptstring = encryptstringtobytes (ciphertext, keybytes, iv);
Return convert.tobase64string (encryptstring);
}
private 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 a RijndaelManaged object
With the specified key and Iv.
using (var rijalg = new RijndaelManaged ())
{
Rijalg.mode = CIPHERMODE.CBC;
rijalg.padding = PADDINGMODE.PKCS7;
rijalg.feedbacksize = 128;
Rijalg.key = Key;
RIJALG.IV = IV;
Create a decrytor to perform the stream transform.
var encryptor = Rijalg.createencryptor (Rijalg.key, RIJALG.IV);
Create the streams used for encryption.
using (var msencrypt = new MemoryStream ())
{
using (var csencrypt = new CryptoStream (Msencrypt, Encryptor, CryptoStreamMode.Write))
{
using (var swencrypt = new StreamWriter (csencrypt))
{
Write all data to the stream.
Swencrypt.write (plaintext);
}
encrypted = Msencrypt.toarray ();
}
}
}
Return the encrypted bytes from the memory stream.
return encrypted;
}
}
}
JavaScript and C#aes encryption method Mutual Solution