Flutter/Dart中的openssl_public_encrypt() [英] openssl_public_encrypt() in Flutter/dart
本文介绍了Flutter/Dart中的openssl_public_encrypt()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用与此php函数相似的东西
openssl_public_encrypt('text', $output, $publicKey, OPENSSL_PKCS1_PADDING);
在Flutter(Dart)中.最简单的方法是什么?谢谢!
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!
推荐答案
您可以使用加密库
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);
这篇关于Flutter/Dart中的openssl_public_encrypt()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文