CryptoNet icon indicating copy to clipboard operation
CryptoNet copied to clipboard

Why can't I decrypt successfully without writing all the content in the same method?

Open simphonydeveloper opened this issue 1 year ago • 0 comments

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;

simphonydeveloper avatar Mar 10 '24 14:03 simphonydeveloper