Comments (4)
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.dart
import '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.dart
import '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:
- Because of padding the resulting binary will never be the same, no matter if is being encrypted on Dart or PHP.
- The binary representation should be interchangeable, for example I used base64 on the snippets.
from encrypt.
Can you share a snippet with this issue, please?
from encrypt.
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.
On the other hand, the php code was this:
<?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.
from encrypt.
Yes, sorry, i just compared they bits and assumed that is a problem. It'll save me, thank you very much.
from encrypt.
Related Issues (20)
- AES 128 CFB decryption
- I can't decrypt the text in 5.0.3 😕 HOT 11
- Output double in size, AES in CTR
- After RSA public key encryption, I am unable to decrypt it. It shows an error message: 'Error: Expected a value of type 'ASN1Integer', but got one of type 'ASN1Sequence'.
- Getting Private Key Issue HOT 1
- Invalid argument(s): Initialization vector must be the same length as block size
- You can add an onProgress
- Invalid argument(s): Invalid or corrupted pad block HOT 6
- Different encrypted output
- Encryption between platforms
- Web release Invalid or corrupted pad block HOT 3
- '(x >= 0) && (x <= _MASK_32)': is not true
- Exception has occurred. ArgumentError (Invalid argument(s): Invalid or corrupted pad block) HOT 11
- About Privacy Manifest HOT 1
- RSAKeyParser is not defined in poiintycastle
- [v5.0.3][Web] decrypt incorrect HOT 6
- crypto dependency issue
- Insecure Random on ios
- Invalid argument(s): Invalid or corrupted pad block HOT 7
- (mistake) `Key.stretch` should be a factory constructor HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from encrypt.