more useful options | |
PerlMonks |
OpenSSL and Crypt::CBC don't give the same ciphertextby LonelyPilgrim (Beadle) |
on Feb 05, 2016 at 23:36 UTC ( [id://1154528]=perlquestion: print w/replies, xml ) | Need Help?? |
LonelyPilgrim has asked for the wisdom of the Perl Monks concerning the following question: Greetings, Wise Monks. I am a wayfarer returned from many travels. I'm taking a Network Security course and am pretty much a novice when it comes to encryption. My assignment asks me to encrypt and decrypt a 1024-byte plaintext (which happens to be a transcript from the opening of Zork) by calling the OpenSSL binary -- but that's kind of slow, I suspect owing in part to the latency of launching new processes and file I/O, so I had (what I thought to be) the bright idea of doing the decryption separately in Perl (using Crypt::CBC) and timing the difference. That's all well and good; doing it the Perl way appears to be considerably faster; but here's my problem: I can't get OpenSSL and Crypt::CBC to give me the same ciphertext. Can anybody help me figure out what I am doing wrong? My code:
Comparing test.bin (the output from OpenSSL) and cryptx.bin (the output from Perl) shows that the two are completely different from the first byte. The files are the same length (1032 bytes) and do not change with each run. UPDATE: I fixed it. Oh, I'm an idiot. Endianness: so simple and yet so important. It should have been H* instead of h* in my pack statements. Fix that, and it gives the right result.
Back to
Seekers of Perl Wisdom
|
|