public async Task <KeyPair> GenerateKey(HandshakeMethod method) { var tmpFilePublic = System.IO.Path.GetTempFileName(); var tmpFilePrivate = System.IO.Path.GetTempFileName(); using var pgp = new PGP(); await pgp.GenerateKeyAsync(tmpFilePublic, tmpFilePrivate); var publicKey = await File.ReadAllTextAsync(tmpFilePublic); var privateKey = await File.ReadAllTextAsync(tmpFilePrivate); return(new KeyPair() { Private = new PrivateKey() { Format = AuthKeyFormat.PEM, Type = Type, Value = privateKey, WhenAdded = DateTime.UtcNow, }, Public = new PublicKey() { Format = AuthKeyFormat.PEM, Type = Type, Value = publicKey.Trim(), WhenAdded = DateTime.UtcNow, }, }); }
public async Task GenerateKeyAsync_CreatePublicPrivateKeyFiles() { // Arrange TestFactory testFactory = new TestFactory(); await testFactory.ArrangeAsync(); PGP pgp = new PGP(); // Act await pgp.GenerateKeyAsync(testFactory.PublicKeyFilePath, testFactory.PrivateKeyFilePath, testFactory.Password); // Assert Assert.True(File.Exists(testFactory.PublicKeyFilePath)); Assert.True(File.Exists(testFactory.PrivateKeyFilePath)); // Cleanup testFactory.Teardown(); }