I need to use something similar to this php function
openssl_public_encrypt('text', $output, $publicKey, OPENSSL_PKCS1_PADDING);
in Flutter (Dart). What is the easiest way to accomplish that? Thank you!
Asked
Active
Viewed 2,097 times
1

Vojtech Psenak
- 56
- 4
1 Answers
2
You can use encrypt library.
import 'dart:io';
import 'package:encrypt/encrypt.dart';
final plainText = 'Lorem ipsum dolor sit amet.';
final publicKey = RSAKeyParser().parse(File('public.pem').readAsStringSync());
final privateKey = RSAKeyParser().parse(File('private.pem').readAsStringSync());
final encrypter = Encrypter(
RSA(
publicKey: publicKey,
privateKey: privateKey,
encoding: RSAEncoding.PKCS1,
),
);
final encrypted = encrypter.encrypt(plainText);
final decrypted = encrypter.decrypt64(encrypted.base64);

janstol
- 2,857
- 1
- 18
- 21