How to Use Python to encrypt and decrypt data in Rijndael mode?

Source: Internet
Author: User
Tags mcrypt
Here is an example of Rijndael encryption using PHP: {code...} I have found this Code. The answer in this code is indeed feasible, but how can I customize iv? (That is, utf8_encode (& #039; fOaiIOkD8 * 9Xeu_s4_bb87Ox_UG + D9GA & #039;) In addition, block_size, key_size, and iv_size are required... the following is an example of Rijndael encryption using PHP:

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')));}

I once found this code, and the answer in it is indeed feasible, but how to customize iv? (That isutf8_encode('fOaiIOkD8*9Xeu_s4_bb87Ox_UG+D9GA'))
In addition,block_size,key_sizeAndiv_sizeThe value must be 32 bytes ).

When mcrypt. c is compiled, the GCC prompts the following error:

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

Reply content:

The following is an example of Rijndael encryption using PHP:

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')));}

I once found this code, and the answer in it is indeed feasible, but how to customize iv? (That isutf8_encode('fOaiIOkD8*9Xeu_s4_bb87Ox_UG+D9GA'))
In addition,block_size,key_sizeAndiv_sizeThe value must be 32 bytes ).

When mcrypt. c is compiled, the GCC prompts the following error:

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.