Austin Muts

Austin Muts

  • 1.1k
  • 329
  • 125.2k

AES 128 -bit Encryption-Decryption in C#

Apr 6 2019 1:46 PM
I am trying to decrypt the given text with the key but i am getting error "The input data is not a complete block"    Check  code below and help if you can .
  1. private string DecryptOTP(string decryptethis)  
  2. {  
  3. decryptethis = "4931cb6f11c9f8b24f0b05f9ec9a2cc0";  
  4. string decryptionKey = string.Empty;  
  5. decryptionKey = "f22704b8bc0dcc606303b5eb97332630";  
  6. byte[] cipherBytes = Convert.FromBase64String(decryptedOTP.Trim());  
  7. using (Aes encryptor = Aes.Create())  
  8. {  
  9. Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(decryptionKey.Trim(), new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });  
  10. encryptor.Key = pdb.GetBytes(32);  
  11. encryptor.IV = pdb.GetBytes(16);  
  12. using (MemoryStream ms = new MemoryStream())  
  13. {  
  14. using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write))  
  15. {  
  16. cs.Write(cipherBytes, 0, cipherBytes.Length);  
  17. cs.Close();  
  18. }  
  19. decryptethis = Encoding.Unicode.GetString(ms.ToArray());  
  20. }  
  21. }  
  22. return decryptethis;  
  23. }

Answers (6)