using System.Security.Cryptography;
private const int HashIterations = 1024;
public static void Main()
var password = "sinagama";
var salt = new Byte[]{172, 137, 25, 56, 156, 100, 136, 211, 84, 67, 96, 10, 24, 111, 112, 137, 3};
byte[] derivedKey = GeneratePasswordHash(password, salt);
string TRANS_ID="DP1000520210628165440";
string MER_TOKEN="VN1Q0UC5IA72QTXW";
string ivKey="1234567890123456";
using (AesManaged myAes = new AesManaged())
byte[] ivkey = Encoding.ASCII.GetBytes(ivKey);
string encryptedTRANS_ID=EncryptStringToBytes_Aes(TRANS_ID, derivedKey, ivkey);
string encryptedTRANS_TYPE=EncryptStringToBytes_Aes(TRANS_TYPE, derivedKey, ivkey);
string encryptedMER_TOKEN=EncryptStringToBytes_Aes(MER_TOKEN, derivedKey, ivkey);
Console.WriteLine("TRANS_ID:{0}", encryptedTRANS_ID);
Console.WriteLine("TRANS_TYPE:{0}", encryptedTRANS_TYPE);
Console.WriteLine("MER_TOKEN:{0}", encryptedMER_TOKEN);
Console.WriteLine("IvKey:{0}", ivKey);
static string EncryptStringToBytes_Aes(string plainText, byte[] Key, byte[] IV)
throw new ArgumentNullException("plainText");
if (Key == null || Key.Length <= 0)
throw new ArgumentNullException("Key");
if (IV == null || IV.Length <= 0)
throw new ArgumentNullException("IV");
using (AesManaged aesAlg = new AesManaged())
ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
using (MemoryStream msEncrypt = new MemoryStream())
using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
swEncrypt.Write(plainText);
encrypted = msEncrypt.ToArray();
return Convert.ToBase64String(encrypted);
public static byte[] GeneratePasswordHash(string password, Byte[] salt, int hashIterations = HashIterations)
using (var crypto = new Rfc2898DeriveBytes(password, salt, hashIterations, HashAlgorithmName.SHA1))
hash = crypto.GetBytes(16);
static string ComputeSha256Hash(string rawData)
using (SHA256 sha256Hash = SHA256.Create())
byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(rawData));
StringBuilder builder = new StringBuilder();
for (int i = 0; i < bytes.Length; i++)
builder.Append(bytes[i].ToString("x2"));
return builder.ToString();