roEVPCipher and FromBase64String

I’m trying to feed the output of roByteArray.FromBase64String() directly into roEVPCipher.Process(), but Process() returns invalid sometimes. To make it work consistently I have to run cryptext through ToHexString() and FromHexString() before hitting Process(). The problem comes and go as the length of cryptext changes. It’s repeatable but I cannot discern any pattern. For all cryptexts that have a problem, ba and ba2 appear to be identical, yet ba cannot be decrypted while ba2 decrypts ok.

Does anyone have any idea what’s going on here?

Does not work:


key = "12345678901234567890123456789012"
iv = "1234567890123456"
cryptext = "a2Lv5D+dKbcd5Al6Zb8Fqk99hMxH86gDJ6bHoroaK5c="
dcrypto = CreateObject("roEVPCipher")
dcrypto.Setup(false,"bf",key,iv,1)
ba = CreateObject("roByteArray")
ba.FromBase64String(cryptext)
print dcrypto.Process(ba).ToAsciiString()

Works Ok - Extra conversion using .ToHexString():


key = "12345678901234567890123456789012"
iv = "1234567890123456"
cryptext = "a2Lv5D+dKbcd5Al6Zb8Fqk99hMxH86gDJ6bHoroaK5c="
dcrypto = CreateObject("roEVPCipher")
dcrypto.Setup(false,"bf",key,iv,1)
ba = CreateObject("roByteArray")
ba.FromBase64String(cryptext)
temp = ba.ToHexString()
ba2 = CreateObject("roByteArray")
ba2.FromHexString(temp)
print dcrypto.Process(ba2).ToAsciiString()

Works Ok - Same as 1st example, but different cryptext length:


key = "12345678901234567890123456789012"
iv = "1234567890123456"
cryptext = "a2Lv5D+dKbcd5Al6Zb8Fqk99hMxH86gDj3Ur0ytpBJg9VAinHfW44GQJywUGmywlbd+5/s7eFcz+1ABpO32n/lQ9ByM4/jXH"
dcrypto = CreateObject("roEVPCipher")
dcrypto.Setup(false,"bf",key,iv,1)
ba = CreateObject("roByteArray")
ba.FromBase64String(cryptext)
print dcrypto.Process(ba).ToAsciiString()

Hello - nothing appears incorrect with the calls you are making. We have filed a bug internally to track this and will investigate.

Cheers,
Jon

The bug is a by-product of the way FromBase64String() works. It happens if the last character in the string is “=”, or if you are using an existing roByteArray that is larger than the result of FromBase64String(). This explains why your 3rd example works fine.

This will be fixed in a future release of the software, but for now your workaround of using ToHexString/FromHexString is probably the best approach.