| | |
Something wrong with the Decrypt function
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2009
Posts: 15
Reputation:
Solved Threads: 0
Hi all,
I am tying to test the code from the following url
http://www.obviex.com/Samples/Encryption.aspx
The following Decrypt code has some issues. It does not give any errors, but the plaintext is not returned either. The corresponding Encrypt code is working fine.
When I provide wrong key during the decryption, i.e. different from what was used in Encrypt function, an error is prompted
Padding is invalid and cannot be removed
This means, that the code is functional but something is not allowing the result to return.
Thanks in advance,
Abhi
I am tying to test the code from the following url
http://www.obviex.com/Samples/Encryption.aspx
The following Decrypt code has some issues. It does not give any errors, but the plaintext is not returned either. The corresponding Encrypt code is working fine.
C# Syntax (Toggle Plain Text)
public static string Decrypt(string cipherText, string passPhrase, string saltValue, string hashAlgorithm, int passwordIterations, string initVector, int keySize) { byte[] initVectorBytes = Encoding.ASCII.GetBytes(initVector); byte[] saltValueBytes = Encoding.ASCII.GetBytes(saltValue); byte[] cipherTextBytes = Convert.FromBase64String(cipherText); PasswordDeriveBytes password = new PasswordDeriveBytes( passPhrase, saltValueBytes, hashAlgorithm, passwordIterations); byte[] keyBytes = password.GetBytes(keySize / 8); RijndaelManaged symmetricKey = new RijndaelManaged(); symmetricKey.Mode = CipherMode.CBC; ICryptoTransform decryptor = symmetricKey.CreateDecryptor( keyBytes, initVectorBytes); MemoryStream memoryStream = new MemoryStream(cipherTextBytes); CryptoStream cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read); byte[] plainTextBytes = new byte[cipherTextBytes.Length]; int decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length); memoryStream.Close(); cryptoStream.Close(); string plainText = Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount); return plainText; }
When I provide wrong key during the decryption, i.e. different from what was used in Encrypt function, an error is prompted
Padding is invalid and cannot be removed
This means, that the code is functional but something is not allowing the result to return.
Thanks in advance,
Abhi
Are you fond of that particular encryption method or are you just want any type of encryption? I have a code sample online at http://www.daniweb.com/code/snippet217409.html with examples of encrypt and decrypt routines.
![]() |
Similar Threads
- wrong # of args in function call printf (C)
- What is wrong with my sorting function? (C++)
- What's wrong with the return of this function call? (C++)
- Function question (C++)
- Windows programming - C - Save file function (C++)
- putting the address of a function pointer into a struct (C)
Other Threads in the C# Forum
- Previous Thread: Declare 2 Dimension for List<String>
- Next Thread: New to this, need help disecting a completed program to an editable form
| Thread Tools | Search this Thread |
add blackmail block browser buttons c++ challenge compression crack data decryption dell ect ediscovery email encryption enterprise firefox ftp government hardware java kioti16 kmip laptop microsoft news opensource password program protection rsa security size softwaredevelopment string sun survey user virus webmail word







