如何使用Python進行Rijndael方式的加密解密?

來源:互聯網
上載者:User
以下是使用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_sizekey_sizeiv_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_sizekey_sizeiv_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
  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.