以下是使用PHP進行Rijndael方式加密的例子:
function encrypt($data) { return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256 ,'oqufXQ(?bc=6_hR2I3sMZChDpb6dDlw4', $data , MCRYPT_MODE_CBC, utf8_encode('fOaiIOkD8*9Xeu_s4_bb87Ox_UG+D9GA')));}
我曾找到這個代碼,裡面的答案的確可行,但如何自訂iv?(即utf8_encode('fOaiIOkD8*9Xeu_s4_bb87Ox_UG+D9GA')
)
另,block_size
、key_size
和iv_size
均需要為32(位元組)。
編譯mcrypt.c,GCC提示錯誤如下:
mcrypt.c: In function 'initmcrypt':mcrypt.c:1714:2: error: incompatible type for argument 1 of 'PyString_FromString'In file included from C:\Python27\include/Python.h:94:0, from mcrypt.c:24:C:\Python27\include/stringobject.h:63:24: note: expected 'const char *' but argument is of type 'double'error: command 'gcc' failed with exit status 1
回複內容:
以下是使用PHP進行Rijndael方式加密的例子:
function encrypt($data) { return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256 ,'oqufXQ(?bc=6_hR2I3sMZChDpb6dDlw4', $data , MCRYPT_MODE_CBC, utf8_encode('fOaiIOkD8*9Xeu_s4_bb87Ox_UG+D9GA')));}
我曾找到這個代碼,裡面的答案的確可行,但如何自訂iv?(即utf8_encode('fOaiIOkD8*9Xeu_s4_bb87Ox_UG+D9GA')
)
另,block_size
、key_size
和iv_size
均需要為32(位元組)。
編譯mcrypt.c,GCC提示錯誤如下:
mcrypt.c: In function 'initmcrypt':mcrypt.c:1714:2: error: incompatible type for argument 1 of 'PyString_FromString'In file included from C:\Python27\include/Python.h:94:0, from mcrypt.c:24:C:\Python27\include/stringobject.h:63:24: note: expected 'const char *' but argument is of type 'double'error: command 'gcc' failed with exit status 1