encrypt
encrypt copied to clipboard
How to confige private key length?
use 'openssl' generate private and public key; It's ok when i set private key length 1024,but it not worked when i set private key length 2048;
opensll version : LibreSSL 2.8.3
openssl genrsa -out rsa_private_1024.key 1024
openssl rsa -in rsa_private_2014.key -pubout -out rsa_public_1024.key
i use this key pair ,everything is ok, but when i generate 2048
openssl genrsa -out rsa_private_2048.key 2048
openssl rsa -in rsa_private_2048.key -pubout -out rsa_public_2048.key
to encrypt is ok, but decrypt not worked, the error message
Unhandled Exception: Invalid argument(s): Unsupported block type for private key: 48
, 48
is not const
sample code
final parser = RSAKeyParser();
final publicKey = parser.parse(publickeyString) as RSAPublicKey;
final privateKey = parser.parse(privateKeyString) as RSAPrivateKey;
final encrypter = Encrypter(RSA(
publicKey: publicKey, privateKey: privateKey, encoding: RSAEncoding.PKCS1));
String sortEncrypt(String source){
final encrypter = Encrypter(RSA(publicKey: publicKey));
return encrypter.encrypt(source).base64;
}
String sortDecrypt(String source){
final encrypter = Encrypter(RSA(privateKey: privateKey));
return encrypter.decrypt(Encrypted.fromBase64(source));
}
void main() {
String raw = "this is test";
String en = sortEncrypt(raw);
String de = sortDecrypt(en);
print(en);
print(de);
}
so, what should i do ?