我正在开发一个以Firebase为数据库的颤动消息应用程序。为了加密两个用户之间发送的消息,我使用rsa-encrypt包在应用程序开始时生成公钥和私钥对。
使用EncryptionData类生成Keypair的代码:
import 'package:rsa_encrypt/rsa_encrypt.dart';
import 'package:pointycastle/api.dart' as crypto;
Future<crypto.AsymmetricKeyPair> futureKeyPair;
crypto.AsymmetricKeyPair keyPair;
class EncryptFunctions{
Future<crypto.AsymmetricKeyPair<crypto.PublicKey,crypto.PrivateKey>> getKeyPair(){
var helper = RsaKeyHelper();
return helper.computeRSAKeyPair(helper.getSecureRandom());
}
}Main.dart是这样的:
void main(){
EncryptFunctions encryptFunctions = new EncryptFunctions();
futureKeyPair = encryptFunctions.getKeyPair();
runApp(MyApp());
}为了加密或解密字符串,我们使用来自同一个包的encrypt()和decrypt()方法。futureKeyPair包含公钥和私钥,可以使用以下命令访问这些密钥
keyPair = await futureKeyPair();如何在设备上安全地存储私钥,以完成端到端加密。这是我在Stackoverflow上的第一个问题。对于任何格式错误,我深表歉意。
发布于 2020-12-29 01:09:41
安卓有KeyChain和KeyStore接口:
https://developer.android.com/reference/android/security/KeyChain
https://developer.android.com/training/articles/keystore.html
iOS有密钥链:
https://developer.apple.com/documentation/security/keychain_services
截至2020年12月,我还不知道有什么flutter包对这些API进行了抽象。
除非你想编写自己的包,否则你可能想要使用的最接近的东西是flutter_secure_storage包,它将密钥对存储在用于安卓的Keystore和用于iOS的密钥链中,然后在存储到SharedPreference (在安卓上)之前使用该密钥对数据进行加密。只需查看代码以了解详细信息。
https://stackoverflow.com/questions/61983145
复制相似问题