We use AES 256 algo rhythm for encryption.
1. Mode : ECB
2. Key Size : 256 bits
3. Secrete key : own key.
4. Output Text format : Base 64 in c#
i am apply multiple C# sharp code but my encrption data is different checking with website(AES Encryption and Decryption Online (devglan.com))
please help any one on urgent basis.....


Mayooran NavamanyRank #438 · 5.7K reputationPosted Jun 23, 2024, 12:28 AM EDT
Here is a simple implementation in C#:
Add the necessary imports:
using System; using System.Security.Cryptography; using System.Text; public class AesEncryption { public static string Encrypt(string plainText, string key) { byte[] keyBytes = Encoding.UTF8.GetBytes(key); byte[] inputBytes = Encoding.UTF8.GetBytes(plainText); using (Aes aesAlg = Aes.Create()) { aesAlg.Key = keyBytes; aesAlg.Mode = CipherMode.ECB; aesAlg.Padding = PaddingMode.PKCS7; ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV); byte[] encryptedBytes = encryptor.TransformFinalBlock(inputBytes, 0, inputBytes.Length); return Convert.ToBase64String(encryptedBytes); } } public static string Decrypt(string encryptedText, string key) { byte[] keyBytes = Encoding.UTF8.GetBytes(key); byte[] encryptedBytes = Convert.FromBase64String(encryptedText); using (Aes aesAlg = Aes.Create()) { aesAlg.Key = keyBytes; aesAlg.Mode = CipherMode.ECB; aesAlg.Padding = PaddingMode.PKCS7; ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV); byte[] decryptedBytes = decryptor.TransformFinalBlock(encryptedBytes, 0, encryptedBytes.Length); return Encoding.UTF8.GetString(decryptedBytes); } } public static void Main(string[] args) { string key = "your_32_byte_long_secret_key_here"; // Must be 32 bytes for AES-256 string original = "Hello, World!"; // Encrypt the string string encrypted = Encrypt(original, key); Console.WriteLine($"Encrypted: {encrypted}"); // Decrypt the string string decrypted = Decrypt(encrypted, key); Console.WriteLine($"Decrypted: {decrypted}"); } }Notes:
key) is exactly 32 bytes long.How to Test:
"your_32_byte_long_secret_key_here"with your actual 32-byte key."Hello, World!"with your actual plaintext data.Sanjeev Kumar55 reputationPosted Jun 24, 2024, 4:34 AM EDT
Hi Sir
a am apply this code but encryption value is different
this code is apply encryption value: DaFIzm+1j3DLhZ4J9pFUzQ==