|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
Problem Decrypting DataHi, I am a newbie to working with CryptLib and was wondering if someone could help me figure out what I am doing wrong decrypting data. I've followed the documentation very carefully and seem to be doing everything correct. But, well, obviously I am not.
This is a simple password encryption using C# [1]. Pretty much the most basic usage of the library, from what I can tell. The one part I am not following to the letter is that I am calling the cryptSetAttribute methods *before* I call cryptPushData.
But when I reverse those two calls, I get an error (and not the expected error telling me I need a password, rather error -21 (No Permission to Perform this Operation.)) Any help would be greatly appreciated. I've tried every variation of this code that I can imagine. The full source of the entire (short, simple) console application is here:
[1] static string DecryptData(string encodedData, string password)
{ byte[] envelopedData = StringToBytes(encodedData); int envelope = crypt.CreateEnvelope(crypt.UNUSED, crypt.FORMAT_CRYPTLIB); crypt.SetAttribute(envelope, crypt.ENVINFO_DATASIZE, envelopedData.Length);
crypt.SetAttributeString(envelope, crypt.ENVINFO_PASSWORD, password); int bytesCopied = 0; try { bytesCopied = crypt.PushData(envelope, envelopedData);
} catch (CryptException cexc) { Console.WriteLine(cexc.ToString()); } crypt.FlushData(envelope);
byte[] messageBuffer = new byte[envelopedData.Length]; bytesCopied = crypt.PopData(envelope, messageBuffer, messageBuffer.Length); string unencryptedData = ASCIIEncoding.ASCII.GetString(messageBuffer);
crypt.DestroyEnvelope(envelope); return unencryptedData; } -- Patrick Burrows _______________________________________________ Cryptlib mailing list Cryptlib@... via Mail: cryptlib-request@... Archive: ftp://ftp.franken.de/pub/crypt/cryptlib/archives/ http://news.gmane.org/gmane.comp.encryption.cryptlib Posts from non-subscribed addresses are blocked to prevent spam, please subscribe in order to post messages. |
|
|
Re: Problem Decrypting Data> The one part I am not following to the letter is that I am calling the
> cryptSetAttribute methods *before* I call cryptPushData. > > But when I reverse those two calls, I get an error (and not the expected > error telling me I need a password, rather error -21 (No Permission to > Perform this Operation.)) > > Any help would be greatly appreciated. When calling crypt.CreateEnvelope(crypt.UNUSED,crypt.FORMAT_CRYPTLIB) you try to encrypt and NOT to decrypt the message! That's why you get an error -21 when you reverse your callind sequence. You have to use crypt.FORMAT_AUTO as second parameter for decryption. Using envelopedData.Length as length of your messageBuffer is not the optimal solution: In case of an encrypted envelope the decrypted length is always shorter than the envelope length, but when you try to de-envelope a compressed envelope, you may get a longer byte string on PopData than you pushed in. Wolfgang Gothier _______________________________________________ Cryptlib mailing list Cryptlib@... via Mail: cryptlib-request@... Archive: ftp://ftp.franken.de/pub/crypt/cryptlib/archives/ http://news.gmane.org/gmane.comp.encryption.cryptlib Posts from non-subscribed addresses are blocked to prevent spam, please subscribe in order to post messages. |
| Free embeddable forum powered by Nabble | Forum Help |