-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need PHP version of this encoding. #87
Comments
Can you share the function you wrote? Is it giving any errors? |
`<?php // Generate an initialization vector // Encrypt $data using aes-256-cbc cipher with the given encryption key and echo "Key: ".base64_encode($encryption_key).PHP_EOL; echo "IV: ".base64_encode($iv).PHP_EOL; echo "Encrypted: $encrypted\n"; |
`<?php $encryption_key = 'rKnJQAMdfHa4jl+INHKi+w=='; $iv = 'YxSYgDGcVWzICnHLnCkXaw=='; $encrypted = "scLHHCHeDD4Oe6raVSLaD375c/4jLSAp/aaTgKLJgFaemTwDyKHMJIIFbUcYJfcS"; // These three value generated from the encrypt code. //print_r($parts); |
Take a look at this 4 working and fully interoperable encryption snippets and adapt to your needs: Dart encryptimport 'package:encrypt/encrypt.dart';
const encodedKey = 'FCAcEA0HBAoRGyALBQIeCAcaDxYWEQQPBxcXHgAFDgY=';
const encodedIv = 'DB4gHxkcBQkKCxoRGBkaFA==';
void main(List<String> args) {
final key = Key.fromBase64(encodedKey);
final iv = IV.fromBase64(encodedIv);
final encrypter = Encrypter(AES(key, mode: AESMode.cbc));
final encrypted = encrypter.encrypt(args[0], iv: iv);
print(encrypted.base64);
} PHP decrypt<?php declare(strict_types=1);
const encodedKey = 'FCAcEA0HBAoRGyALBQIeCAcaDxYWEQQPBxcXHgAFDgY=';
const encodedIv = 'DB4gHxkcBQkKCxoRGBkaFA==';
function main(array $args) {
$key = base64_decode(encodedKey);
$iv = base64_decode(encodedIv);
$encrypter = 'aes-256-cbc';
$decrypted = openssl_decrypt($args[0], $encrypter, $key, 0, $iv);
echo $decrypted;
};
main(array_slice($argv, 1)); Dart decryptimport 'package:encrypt/encrypt.dart';
const encodedKey = 'FCAcEA0HBAoRGyALBQIeCAcaDxYWEQQPBxcXHgAFDgY=';
const encodedIv = 'DB4gHxkcBQkKCxoRGBkaFA==';
void main(List<String> args) {
final key = Key.fromBase64(encodedKey);
final iv = IV.fromBase64(encodedIv);
final encrypter = Encrypter(AES(key, mode: AESMode.cbc));
final decrypted = encrypter.decrypt(Encrypted.fromBase64(args[0]), iv: iv);
print(decrypted);
} PHP encrypt<?php declare(strict_types=1);
const encodedKey = 'FCAcEA0HBAoRGyALBQIeCAcaDxYWEQQPBxcXHgAFDgY=';
const encodedIv = 'DB4gHxkcBQkKCxoRGBkaFA==';
function main(array $args) {
$key = base64_decode(encodedKey);
$iv = base64_decode(encodedIv);
$encrypter = 'aes-256-cbc';
$encrypted = openssl_encrypt($args[0], $encrypter, $key, 0, $iv);
echo $encrypted;
};
main(array_slice($argv, 1)); |
Closed due inactivity. |
Can you please share the PHP version of the same encrypt and decrypt function, thus we can achieve the same process API vice-versa. We wrote the function it didn't get any chance to work
The text was updated successfully, but these errors were encountered: