Hello World!
This is a test of BrightScript encryption...
I hope I can get it to work!
-Kevin
-bash-3.1$ openssl bf -a -A -in test.txt -out test.b64 -k RokuRocks -nosalt -p
key=7B1CB530521E7554D623E1412A2CF29F
iv =785BC65A9D7850FD
html = CreateObject("roUrlTransfer")
ba = CreateObject("roByteArray")
result = CreateObject("roByteArray")
html.SetUrl("http://myserver.com/roku/test.txt")
test = html.GetToString()
html.SetUrl("http://myserver.com/roku/test.b64")
b64 = html.GetToString()
print b64
print test
ba.fromBase64String(b64)
' ba.fromAsciiString(test)
enc = CreateObject("roEVPCipher")
ret = enc.Setup(false, "bf", "7B1CB530521E7554D623E1412A2CF29F", "785BC65A9D7850FD", 1)
print ret
result = enc.Process(ba)
if result <> invalid then
print result.toAsciiString()
' print result.toBase64String()
else
print "Invalid"
end if
Sub getFiles()
html = CreateObject("roUrlTransfer")
ba = CreateObject("roByteArray")
result = CreateObject("roByteArray")
html.SetUrl("http://www.yungblood.com/roku/bad.txt")
test = html.GetToString()
html.SetUrl("http://www.yungblood.com/roku/bad.b64")
b64 = html.GetToString()
html.SetUrl("http://www.yungblood.com/roku/bad.des3")
des3 = html.GetToString()
print b64
print test
ba.fromAsciiString(test)
enc = CreateObject("roEVPCipher")
ret = enc.Setup(true, "bf", "7B1CB530521E7554D623E1412A2CF29F", "785BC65A9D7850FD", 1)
print ret
result = enc.Process(ba)
if result <> invalid then
if result.toBase64String() = b64 then
print "Good Encrypt"
else
print "Bad Encrypt"
end if
else
print "Invalid Encrypt"
end if
ba.fromBase64String(b64)
enc = CreateObject("roEVPCipher")
ret = enc.Setup(false, "bf", "7B1CB530521E7554D623E1412A2CF29F", "785BC65A9D7850FD", 1)
print ret
result = enc.Process(ba)
if result <> invalid then
if result.toAsciiString() = test then
print "Good Decrypt"
else
print "Bad Decrypt"
end if
else
print "Invalid Decrypt"
end if
ba.fromAsciiString(test)
enc = CreateObject("roEVPCipher")
ret = enc.Setup(true, "des3", "7B1CB530521E7554D623E1412A2CF29F785BC65A9D7850FD", "4A74A7EC4B95842A", 1)
print ret
result = enc.Process(ba)
if result <> invalid then
if result.toBase64String() = des3 then
print "Good Encrypt"
else
print "Bad Encrypt"
' Can't even get Encrypt's to match... Close, but not quite.
print des3
print result.toBase64String()
end if
else
print "Invalid Encrypt"
end if
ba.fromBase64String(des3)
enc = CreateObject("roEVPCipher")
ret = enc.Setup(false, "des3", "7B1CB530521E7554D623E1412A2CF29F785BC65A9D7850FD", "4A74A7EC4B95842A", 1)
print ret
result = enc.Process(ba)
if result <> invalid then
if result.toAsciiString() = test then
print "Good Decrypt"
else
print "Bad Decrypt"
end if
else
print "Invalid Decrypt"
end if
End Sub
Function crypto_decrypt(decryptKey As String, IV As String, text As String) As String
crypto = CreateObject("roEVPCipher")
crypto.Setup(false, "bf",decryptKey,IV,1)
ba = CreateObject("roByteArray")
ba.FromHexString(text)
return crypto.Process(ba).ToAsciiString()
End function
Function crypto_encrypt(encryptKey As String, IV As String, text As String) As String
crypto = CreateObject("roEVPCipher")
crypto.Setup(true, "bf",encryptKey,IV,1)
ba = CreateObject("roByteArray")
ba.FromAsciiString(text)
return lcase(crypto.Process(ba).ToHexString())
End function
print "**************************"
print test
print "**************************"
encryptKey = "7B1CB530521E7554D623E1412A2CF29F"
IV = "785BC65A9D7850FD"
encResult = crypto_encrypt(encryptKey, IV, test)
print "**************************"
print encResult
print "**************************"
decResult = crypto_decrypt(encryptKey, IV, encResult)
print "**************************"
print decResult
print "**************************"