I want use JavaScript to write an script to create a hash string, but this string should use some formula which my server side programmer use this in his code,
the C# code for decoding is :
private string Decrypt(string cipherText)
{
string EncryptionKey = "MAKV2SPBNI99212";
byte[] cipherBytes = Convert.FromBase64String(cipherText);
using (Aes encryptor = Aes.Create())
{
Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
encryptor.Key = pdb.GetBytes(32);
encryptor.IV = pdb.GetBytes(16);
using (MemoryStream ms = new MemoryStream())
{
using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write))
{
cs.Write(cipherBytes, 0, cipherBytes.Length);
cs.Close();
}
cipherText = Encoding.Unicode.GetString(ms.ToArray());
}
}
return cipherText;
}
I don't have any idea to working on encrypt/decrypt strings in JavaScript. How can I write an script to encrypt strings in javascript ?
UPDATE:
I found CryptoJS
and use this code:
var ID = 12345;
var ciphertext = Crypto.AES.encrypt(ID, 'MAKV2SPBNI99212');
But the hashed string cannot accept by c# Decrypt
method.