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: 
mjames
Visitor

Unable to get AES 128 encryption/decryption working

I have already looked at the thread viewtopic.php?f=34&t=40497 and tried to follow up on that thread – it does not seem to help.

I am unable to figure out how to use AES 128 encryption. Roku box keeps rebooting in most of the attempts. Otherwise, setup call returns -1. It is working fine if I use "bf” and a 64 bit initialization vector.

Appreciate your help.

Here is my code snippet - wondering if I am doing something wrong

alg = "aes-128-cbc"
pad = 1
encryptKey = "10a58869d74be5a374cf867cfb473859"
IV = "00000000000000000000000000000000"
plainText = "00000000000000000000000000000000"

encResult = crypto_encrypt(alg, encryptKey, IV, plainText, pad)


Function crypto_encrypt(alg as String, encryptKey As String, IV As String, text As String, pad as Integer) As String

crypto = CreateObject("roEVPCipher")
res = crypto.Setup(true, alg,encryptKey,IV,pad)
print res

ba = CreateObject("roByteArray")
ba.FromAsciiString(text)

enc = crypto.Process(ba)

return enc.ToHexString()

End function
0 Kudos
6 REPLIES 6
RokuKevin
Visitor

Re: Unable to get AES 128 encryption/decryption working

Nothing wrong with your code. It works fine on a Roku2.

I can recreate the crash on a Roku1... It's a bug we'll have to look into at some point, but we don't anticipate a patch release anytime soon.

If this is truly required, I suggest utilizing the "Required Feature: Roku 2" when submitting your channel for publishing.

--Kevin
0 Kudos
mjames
Visitor

Re: Unable to get AES 128 encryption/decryption working

Thanks Kevin. It is working on Roku2.
0 Kudos
vinodmangalath
Binge Watcher

Re: Unable to get AES 128 encryption/decryption working

alg ="aes-128-cbc"
pad = 1
encryptKey ="d4fcf78158762c2b"
IV ="d8fcf78848762c4b"
plainText = token
encResult = crypto_encrypt(alg,encryptKey,IV,plainText,pad)

function crypto_encrypt(alg, encryptKey, IV, plainText, pad)
encrypt = false
crypto = CreateObject("roEVPCipher")
res = crypto.Setup(encrypt,alg,encryptKey,IV,pad)

ba = CreateObject("roByteArray")
ba.FromAsciiString(plainText)
enc = crypto.Process(ba)
return (enc.ToBase64String())

end function

 

 

this is my code for aes-128-cbc decryption. but i'm not able to setUp cipher.  setup always call -1.Please suggest me, how to use aes-128-cbc cipher decryption

0 Kudos
renojim
Community Streaming Expert

Re: Unable to get AES 128 encryption/decryption working

Your key and IV should be 16 hex characters.  Yours are only 8.

Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos
vinodmangalath
Binge Watcher

Re: Unable to get AES 128 encryption/decryption working

plaintext = "DWFf4sXI0idwUcQ8lMdung=="
cipher= "aes-128-cbc"
decryptKey= "2b7e151628aed2a6abf7158809cf4f3c"
IV ="000102030405060708090a0b0c0d0e0f"
pad = 1
decResult = crypto_decrypt(cipher, decryptKey, IV, plaintext, pad)

 


Function crypto_decrypt(cipher as String, decryptKeyAs String, IV As String, plaintext As String, pad as Integer) As String
crypto = CreateObject("roEVPCipher")
res = crypto.Setup(false, cipher,decryptKey,IV,pad)
print res
ba = CreateObject("roByteArray")
ba.FromBase64String(plaintext)
enc = crypto.Process(ba)
?"enc"enc
return enc.ToAsciiString()'
End function

 when i trying to process its showing invalid. . any thoughts?

0 Kudos
white-wolf
Reel Rookie

Re: Unable to get AES 128 encryption/decryption working

looks like AES 128 only accepts encryption/decryption key 16 bytes long , your is bigger

 

encryptKey = "10a58869d74be5a374cf867cfb473859"

a key like this should be working

 10a58869d74be5a3 

16 bytes key for AES-128 encryption (16 * 8 = 128)

https://crypto.stackexchange.com/questions/44271/what-is-the-maximum-key-size-for-a-128-bit-aes

 

 

0 Kudos