-
Notifications
You must be signed in to change notification settings - Fork 140
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
RSA encrypted with dart doesn't match with PHP #42
Comments
Can you share a snippet with this issue, please? |
Well, th Dart code was in example, and i used the same key since my keys doesn't worked , i dunno why, i guess it was the bit length. The code was provided here https://github.com/leocavalcante/encrypt/blob/master/example/rsa.dart i just changed the text for my name. <?php
$key = file_get_contents('public.pem');
$string = "joao paulo";
openssl_public_encrypt($string,$cripted,$key, ***);
var_dump(unpack('C*',$cripted ));
echo $cripted;
?> where *** means that i tried every padding avaible. |
Hi @zerocoll9 A just created 4 snippets: encrypt.php<?php
$key = file_get_contents('public.pem');
openssl_public_encrypt($argv[1], $encrypted, $key);
echo base64_encode($encrypted);
?> decrypt.php<?php
$key = file_get_contents('private.pem');
openssl_private_decrypt(base64_decode($argv[1]), $decrypted, $key);
echo $decrypted; encrypt.dartimport 'dart:io';
import 'package:encrypt/encrypt.dart';
void main(List<String> args) {
final publicKey = RSAKeyParser().parse(File('public.pem').readAsStringSync());
final encrypter = Encrypter(RSA(publicKey: publicKey));
final encrypted = encrypter.encrypt(args[0]);
print(encrypted.base64);
} decrypt.dartimport 'dart:io';
import 'package:encrypt/encrypt.dart';
void main(List<String> args) {
final privKey = RSAKeyParser().parse(File('private.pem').readAsStringSync());
final encrypted = Encrypted.fromBase64(args[0]);
final encrypter = Encrypter(RSA(privateKey: privKey));
final decrypted = encrypter.decrypt(encrypted);
print(decrypted);
} And they are fully interoperable: Terminal$ dart .\decrypt.dart (php .\encrypt.php "encrypt on php and decrypt on dart")
encrypt on php and decrypt on dart
$ php .\decrypt.php (dart .\encrypt.dart "encrypt on dart and decrypt on php")
encrypt on dart and decrypt on php I think you are missing two points here:
|
Yes, sorry, i just compared they bits and assumed that is a problem. It'll save me, thank you very much. |
I tried to encrypt a string in dart with Encrypt, but, when i compared it with that openssl on php gave me, it didn't match. I tried every padding avaible.
The text was updated successfully, but these errors were encountered: