Code: Select all
Procedure.s AESCBCEncrypt(text.s,password.s,InitializationVector.s,method.l=128,padding.l=1,flag.l=#PB_UTF8)
;padding--0表示ZeroPadding;1表示pkcs7padding/pkcs5padding(通过其他软件测试没有发现加密结果不一样)
;padding--0 represents "ZeroPadding";1 represents "pkcs7padding"/"pkcs5padding"(It seems that, there is no different encryption results found through other software tests.)
Protected.i Length, pokelen, slen, i
Protected *KeyAES, *iv, *InAES, *outAES
Protected.s rst
*KeyAES = AllocateMemory(32)
*iv = AllocateMemory(32)
If *KeyAES And *iv
If StringByteLength(password, flag) <= 32 And StringByteLength(InitializationVector, flag) <= 32
PokeS(*KeyAES, password, -1, flag|#PB_String_NoZero)
PokeS(*iv, InitializationVector, -1, flag|#PB_String_NoZero)
slen = StringByteLength(text, flag)
pokelen=16-(slen%16)
Length=slen+Pokelen
*InAES = AllocateMemory(Length)
PokeS(*InAES, text, -1, flag)
If *InAES
For i=0 To pokelen-1
Select padding
Case 0
PokeA(*InAES+slen+i,0)
Case 1
PokeA(*InAES+slen+i,Pokelen)
EndSelect
Next
*outAES = AllocateMemory(Length)
If *outAES
If AESEncoder(*inAES, *outAES, Length, *KeyAES, method, *iv, #PB_Cipher_CBC)
rst=Base64Encoder(*outAES, Length)
EndIf
FreeMemory(*outAES)
EndIf
FreeMemory(*InAES)
EndIf
EndIf
FreeMemory(*KeyAES)
EndIf
ProcedureReturn rst
EndProcedure
;####测试代码/testCode##########################################
; Define e$
; e$=AESCBCEncrypt("1234567890AESEncrypt","12345678abcdefgh","0102030405060708")
; Debug e$
