AESCipher commands working?
Posted: Wed Oct 18, 2017 10:44 am
I'm not sure if the AESCipher commands are not working or if I'm doing something wrong.
I've contrived this little snippet to demonstrate:
I've contrived this little snippet to demonstrate:
Code: Select all
Procedure.i StringByteLength(sdata.s)
nsize = 0
!v_nsize = new Blob([v_sdata]).size;
ProcedureReturn nsize
EndProcedure
Procedure.s EncryptData(sData$,sKey$,sIV$)
nDataLength = StringByteLength(sData$)
*key = AllocateMemory(40)
*iv = AllocateMemory(40)
*bfrIn = AllocateMemory(nDataLength + 10)
*bfrOut = AllocateMemory(nDataLength * 2)
PokeS(*key,0,sKey$,32)
PokeS(*iv,0,sIV$,32)
PokeS(*bfrIn,0,sData$,nDataLength)
sRes$ = "Didn't work :-("
nRes = StartAESCipher(#PB_Any,*key,256,*iv,#PB_Cipher_Encode|#PB_Cipher_CBC)
If nRes
AddCipherBuffer(nRes,*bfrIn,0,*bfrOut,0,nDataLength)
FinishCipher(nRes)
sRes$ = PeekS(*bfrOut,-1)
EndIf
FreeMemory(*key)
FreeMemory(*iv)
FreeMemory(*bfrIn)
FreeMemory(*bfrOut)
ProcedureReturn sRes$
EndProcedure
sData.s = "Something to encrypt"
sKey.s = "**A32ByteLongPasswordIsUnusual**"
sIV.s = "ABCDEFGHIJKLMONPQRSTUVWXYZabcdef"
Debug EncryptData(sData,sKey,sIV)