Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main()
- {
- //string publicKeyFile = File.ReadAllText("E:\\publickey.rsa");
- string privateKeyFile = File.ReadAllText("E:\\privatekey.rsa");
- string cipherFile = File.ReadAllText("E:\\cipher.rsa");
- //Convert base64 to DER
- byte[] privateKeyArr = Convert.FromBase64String(privateKeyFile);
- Console.WriteLine(cipherFile.Length);
- //Dump the bytes to .der file
- File.WriteAllBytes("private-key.der", privateKeyArr);
- byte[] cipherArr = Convert.FromBase64String(cipherFile);
- //Load the der file
- AsnKeyParser keyParser = new AsnKeyParser("private-key.der");
- RSAParameters privateKey = keyParser.ParseRSAPrivateKey();
- CspParameters csp = new CspParameters();
- csp.KeyContainerName = "RSA Test (OK to Delete)";
- csp.ProviderType = 1;
- csp.KeyNumber = 1;
- RSACryptoServiceProvider rsp = new RSACryptoServiceProvider(csp);
- rsp.PersistKeyInCsp = false;
- rsp.ImportParameters(privateKey);
- //Causes exception here..
- var data = rsp.Decrypt(cipherArr, true);
- string text = Encoding.Default.GetString(data);
- Console.WriteLine(text);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement