myloveCc / NETCore.Encrypt

NETCore encrypt and decrypt tool,Include aes,des,rsa,md5,sha1,sha256,sha384,sha512
MIT License
614 stars 155 forks source link

NETCore.Encrypt.OutofMaxlengthException trying to encrypt 123 #27

Closed Denis-Evseev closed 5 years ago

Denis-Evseev commented 5 years ago

Do you know why var encrypted = EncryptProvider.RSAEncrypt(publicKey, "123");

Retrieves: {"Exception of type 'NETCore.Encrypt.OutofMaxlengthException' was thrown."}

publicKey:

        private const string publicKey =
        @"{""Modulus"": ""m9c88+sazyrDZv7Amrek2MCkkx0ZkHfWXCCPZuZwT8gKEH4m/VDKj6hTVNr0GbZy8ZKtiq9NAxoS5Vr+xdsE9mVJu7XmU/s+D1GnF3cubckivKzCvs63sQQ9JpGmrOkIlfGbmGUprO0HEt3FA2fua/nGh67ApyLPykYXjMQI5QE="",
""Exponent"": ""AQAB""}";

`

catcherwong commented 5 years ago

You can try to specify the RSAEncryptionPadding, the default value is RSAEncryptionPadding.OaepSHA512.

var encrypted = EncryptProvider.RSAEncrypt(key, srcString, RSAEncryptionPadding.Pkcs1);
Denis-Evseev commented 5 years ago

Can I use nopadding - Is it safe?

Do you if it is possible to decrypt/encrypt data using PEM private/public keys?