php端加密解密代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
<?php // Store a string into the variable which // need to be Encrypted $simple_string = "Data to be encrypted"; // Display the original string echo "Original String: " . $simple_string; // Store the cipher method $ciphering = "AES-256-CBC"; // Use OpenSSl Encryption method $iv_length = openssl_cipher_iv_length($ciphering); $options = 0; // Non-NULL Initialization Vector for encryption $encryption_iv = 'Example of IV123'; // Store the encryption key $encryption_key = "12345678901234567890123456789012"; // Use openssl_encrypt() function to encrypt the data $encryption = openssl_encrypt($simple_string, $ciphering, $encryption_key, $options, $encryption_iv); // Display the encrypted string echo "Encrypted String: " . $encryption . "\n"; // Non-NULL Initialization Vector for decryption $decryption_iv = 'Example of IV123'; // Store the decryption key $decryption_key = "12345678901234567890123456789012"; // Use openssl_decrypt() function to decrypt the data $decryption=openssl_decrypt ($encryption, $ciphering, $decryption_key, $options, $decryption_iv); // Display the decrypted string echo "Decrypted String: " . $decryption; |
salesforce端加密解密代码
1 2 3 4 5 6 7 8 9 10 11 12 |
Blob exampleIv = Blob.valueOf('Example of IV123'); Blob key = Blob.valueOf('12345678901234567890123456789012'); system.debug('key'+key.size()); Blob data = Blob.valueOf('Data to be encrypted'); Blob encrypted = Crypto.encrypt('AES256', key, exampleIv, data); system.debug('$encrypted '+EncodingUtil.base64encode(encrypted)); //Blob decrypted = Crypto.decrypt('AES128', key, exampleIv, encrypted); //String decryptedString = decrypted.toString(); //System.debug('Data to be encrypted'+decryptedString); |