CryptoNet
CryptoNet copied to clipboard
Why can't I decrypt successfully without writing all the content in the same method?
Environment: win10 .NET VERSION: .NET6 Application: WebAPI
These my generate key method.
ICryptoNet cryptoNet = new CryptoNetRsa();
string PrivateKeyFile = Path.Combine(AppContext.BaseDirectory, "privateKey");
string PublicKeyFile = Path.Combine(AppContext.BaseDirectory, "publicKey.pub");
cryptoNet.ExportKeyAndSave(new FileInfo(PrivateKeyFile), true);
cryptoNet.ExportKeyAndSave(new FileInfo(PublicKeyFile), false);
encrypt code
ICryptoNet cryptoNetPubKey = new CryptoNetRsa(new FileInfo(key));
var encrypt = cryptoNetPubKey.EncryptFromString("1");
return Convert.ToBase64String(encrypt);
decrypt code
ICryptoNet cryptoNetPriKey = new CryptoNetRsa(new FileInfo(key));
var decrypt = cryptoNetPriKey.DecryptToString(Convert.FromBase64String(data));
return decrypt;