问题描述
我正在用dart构建一个简单的加密工具。
我需要使用密码对rsa私钥进行加密。
我正在使用AES进行加密。
AES要求密钥为特定编号。位。
在我的情况下为256位。
因此,我需要将密码短语扩展到完整的256位。
目前,我只是将密码短语加倍,然后将结果裁剪为256位。
这是正确的做法还是更安全的填充密钥的方法?
我正在使用基于java bouncycastle库的dart pointycastle库。
更新
这是我最近的尝试
class StrongKey extends Key {
StrongKey.fromPassphrase(String passphrase) : super.fromUtf8(passphrase);
Key secureStretch(Uint8List salt) {
return stretch(256,iterationCount: 100000,salt: salt);
}
@override
Key stretch(int desiredKeyLength,{int iterationCount = 100,Uint8List salt}) {
final params = Pbkdf2Parameters(salt,iterationCount,desiredKeyLength);
final pbkdf2 = PBKDF2KeyDerivator(Mac('SHA-512/HMAC'))..init(params);
return Key(pbkdf2.process(bytes));
}
static Uint8List get generateSalt => SecureRandom(256).bytes;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)