Download PowerShell-master/test/xUnit/csharp/test_CryptoUtils.cs from MegaBites-AI/Windows-powershell: direct link, hf CLI and curl.
- Browser
- Download file 1.58 kB
-
https://huggingface.co/datasets/MegaBites-AI/Windows-powershell/resolve/main/PowerShell-master/test/xUnit/csharp/test_CryptoUtils.cs
- Command line
-
hf download hf://datasets/MegaBites-AI/Windows-powershell/PowerShell-master/test/xUnit/csharp/test_CryptoUtils.cs
-
curl -L -o test_CryptoUtils.cs https://huggingface.co/datasets/MegaBites-AI/Windows-powershell/resolve/main/PowerShell-master/test/xUnit/csharp/test_CryptoUtils.cs
1.58 kB
| // Copyright (c) Microsoft Corporation. | |
| // Licensed under the MIT License. | |
| using System; | |
| using System.Management.Automation.Internal; | |
| using System.Text; | |
| using Xunit; | |
| namespace PSTests.Parallel | |
| { | |
| public static class CryptoUntilsTests | |
| { | |
| [] | |
| public static void TestSessionKeyExchange() | |
| { | |
| using (var cryptoClient = PSRSACryptoServiceProvider.GetRSACryptoServiceProviderForClient()) | |
| using (var cryptoServer = PSRSACryptoServiceProvider.GetRSACryptoServiceProviderForServer()) | |
| { | |
| // generate, export, import public key | |
| cryptoClient.GenerateKeyPair(); | |
| // public key generated by client | |
| string publicKey = cryptoClient.GetPublicKeyAsBase64EncodedString(); | |
| cryptoServer.ImportPublicKeyFromBase64EncodedString(publicKey); // sent to and imported by server | |
| // generate, export, import session key | |
| cryptoServer.GenerateSessionKey(); // server provides the session key? | |
| string sessionKey = cryptoServer.SafeExportSessionKey(); | |
| cryptoClient.ImportSessionKeyFromBase64EncodedString(sessionKey); | |
| // encrypt | |
| byte[] plainText = Encoding.UTF8.GetBytes("here is a message"); | |
| byte[] cipherText = cryptoClient.EncryptWithSessionKey(plainText); | |
| // decrypt | |
| byte[] decrypt = cryptoServer.DecryptWithSessionKey(cipherText); | |
| Assert.Equal(plainText, decrypt); | |
| } | |
| } | |
| } | |
| } | |