/
githubmirror
/
PowerShell
Обзор
Документация
Войти
/
githubmirror
/
PowerShell
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
test/xUnit/csharp/test_CryptoUtils.cs
41 строка
2 KB
xtqqczze
Fix `SA1028`: Code should not contain trailing whitespace. Part 1. (#26203)
16 окт 2025, 10:58
Не верифицирован
16 окт 2025, 10:58
a10ff10
Код
Авторство
О чём код?
// 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 { [Fact] 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); } } } }