Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
OddScott
Roku Guru

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()
www.InstantTvChannel.com - 717-441-4386 - Build a Roku SDK channel in 15 minutes! - Easy Direct Publisher to SDK upgrades!
0 Kudos
2 REPLIES 2
Anonymous
Visitor

Re: roEVPCipher and FromBase64String

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

Cheers,
Jon
0 Kudos
RokuKevinG
Visitor

Re: roEVPCipher and FromBase64String

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.
0 Kudos