Node. js-php and nodejs encrypted data Interconnection

Source: Internet
Author: User
Tags php write
The following is an example of the Code for encryption and decryption in nodejs: {code...} How can php write the corresponding encryption and decryption code? It is required that the encrypted data such as Gpkr1WGBFhMvNdHr0eaBg can also be decrypted to nodejs. The following is an example of the Code for encryption and decryption of nodejs:

#! /Usr/bin/env node var crypto = require ('crypto'); // decrypt function decode (cryptkey, iv, secretdata) {var decipher = crypto. createDecipheriv ('aes-256-cbc', cryptkey, iv), decoded = decipher. update (secretdata, 'base64', 'utf8'); decoded + = decipher. final ('utf8'); return decoded;} // decrypt function encode (cryptkey, iv, cleardata) {var encipher = crypto. createCipheriv ('aes-256-cbc', cryptkey, iv), encoded = encipher. update (cleardata, 'utf8', 'base64'); encoded + = encipher. final ('base64'); return encoded;} var cryptkey = crypto. createHash ('sha256 '). update ('_ tazai_wolf _ key '). digest (), iv = '000000', buf = "Hello World", enc = encode (cryptkey, iv, buf); var dec = decode (cryptkey, iv, enc ); function b64enc (data) {var B = new Buffer (data, 'binary '); return B. toString ('base64');} console. warn ("Encoded length:", enc); console. warn ("Decoded all:" + dec );

How can I write the corresponding encryption and decryption code in php?
The above encrypted data, such as Gpkr1WGBFhMvNd/Hr0eaBg =
Data can also be encrypted to nodejs for decryption.

Reply content:

The following is an example of the Code for encryption and decryption of nodejs:

#! /Usr/bin/env node var crypto = require ('crypto'); // decrypt function decode (cryptkey, iv, secretdata) {var decipher = crypto. createDecipheriv ('aes-256-cbc', cryptkey, iv), decoded = decipher. update (secretdata, 'base64', 'utf8'); decoded + = decipher. final ('utf8'); return decoded;} // decrypt function encode (cryptkey, iv, cleardata) {var encipher = crypto. createCipheriv ('aes-256-cbc', cryptkey, iv), encoded = encipher. update (cleardata, 'utf8', 'base64'); encoded + = encipher. final ('base64'); return encoded;} var cryptkey = crypto. createHash ('sha256 '). update ('_ tazai_wolf _ key '). digest (), iv = '000000', buf = "Hello World", enc = encode (cryptkey, iv, buf); var dec = decode (cryptkey, iv, enc ); function b64enc (data) {var B = new Buffer (data, 'binary '); return B. toString ('base64');} console. warn ("Encoded length:", enc); console. warn ("Decoded all:" + dec );

How can I write the corresponding encryption and decryption code in php?
The above encrypted data, such as Gpkr1WGBFhMvNd/Hr0eaBg =
Data can also be encrypted to nodejs for decryption.

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.