I am attempting to use AESEncryption in Purebasic. I want to be able to encrypt/decrypt strings with AES-256. I am using #PB_Cipher_CBC so I need to have a 32bit key and 16bit vector. In my code I am deriving the key and vector bytes from the fingerprint (SHA3) of a given string. I chop up the first 64 bytes of the fingerprint into 32 pairs of Hex strings which the value of are poked into a memory buffer to be read as the Key. Likewise, the last 32 bytes of the fingerprint are chopped up into 16 pairs of Hex strings which the value of each are poked into a memory buffer to be read as the Vector.
If you run my code you'll see that the bytes that are poked into the memory buffers (for the key and vector) are not what is being peeked from each buffer. When I point AESEncoder to the key and vector buffers I don't believe the values are correct.
Not sure if I'm explaining this correctly but if anyone could lend a hand I would be extremely grateful. Thank you.
Code: Select all
UseSHA3Fingerprint()
Procedure DeriveKey(Password.s, *Key, *InitVect)
Fingerprint.s = StringFingerprint(Password, #PB_Cipher_SHA3, 512)
Key.s = Left(Fingerprint, 64)
InitVect.s = Right(Fingerprint, 32)
Debug "FingerPrint: " + Fingerprint
Debug "Key String: " + Key
Debug "Vect String: " + InitVect
;Key
Counter.b = 0
Debug ""
Debug "Key"
Debug "==="
For C = 1 To 64 Step 2
ByteString.s = "$" + Mid(Key, C, 2)
Debug ByteString + " = " + Val(ByteString)
PokeB(*Key + Counter, Val(ByteString))
Counter+1
Next
;InitVect
Counter.b = 0
Debug ""
Debug "InitVect"
Debug "========"
For C = 1 To 32 Step 2
ByteString.s = "$" + Mid(InitVect, C, 2)
Debug ByteString + " = " + Val(ByteString)
PokeB(*InitVect + Counter, Val(ByteString))
Counter+1
Next
EndProcedure
*Key = AllocateMemory(32)
*InitVect = AllocateMemory(16)
DeriveKey("iamjustarandomstring", *Key, *InitVect)
Debug ""
Debug "Peeked key"
Debug "========"
For C = 0 To 31
Debug PeekB(*Key + C)
Next
Debug ""
Debug "Peeked vect"
Debug "========"
For C = 0 To 15
Debug PeekB(*InitVect + C)
Next



