| |
| |
|
|
| using System; |
| using System.Management.Automation.Internal; |
| using System.Text; |
| using Xunit; |
|
|
| namespace PSTests.Parallel |
| { |
| public static class CryptoUntilsTests |
| { |
| [Fact] |
| public static void TestSessionKeyExchange() |
| { |
| using (var cryptoClient = PSRSACryptoServiceProvider.GetRSACryptoServiceProviderForClient()) |
| using (var cryptoServer = PSRSACryptoServiceProvider.GetRSACryptoServiceProviderForServer()) |
| { |
| |
| cryptoClient.GenerateKeyPair(); |
| |
| string publicKey = cryptoClient.GetPublicKeyAsBase64EncodedString(); |
| cryptoServer.ImportPublicKeyFromBase64EncodedString(publicKey); |
|
|
| |
| cryptoServer.GenerateSessionKey(); |
| string sessionKey = cryptoServer.SafeExportSessionKey(); |
| cryptoClient.ImportSessionKeyFromBase64EncodedString(sessionKey); |
|
|
| |
| byte[] plainText = Encoding.UTF8.GetBytes("here is a message"); |
| byte[] cipherText = cryptoClient.EncryptWithSessionKey(plainText); |
|
|
| |
| byte[] decrypt = cryptoServer.DecryptWithSessionKey(cipherText); |
|
|
| Assert.Equal(plainText, decrypt); |
| } |
| } |
| } |
| } |
|
|