6
Answers

AES 128 -bit Encryption-Decryption in C#

Austin Muts

Austin Muts

6y
2.6k
1
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)
1
Ramesh Palanivel

Ramesh Palanivel

205 9.6k 1.5m Nov 25

Hello Tarun,

I recommend, try with another company as now a days most of the organizaiton are using cloud and latest microsoft technologies. Your job is not secured on this new start up as they are not stable now. If you want to work with lastest technologies and you need job security , be patient and upgrade your skill on latest technologies and give a try with best IT industries. Don't settle for current situation.

Accepted