public void SetupAsymmetricKeyProviderTest() { var configuration = Mock.Of <IConfiguration>(c => c.Get <int>("SaltLengthInBytes") == 100 && c.Get <int>("KeyDerivationIterationCount") == 10); var secureRandom = new SecureRandomGenerator(); var asymmetricKeyPairGenerator = new AsymmetricKeyPairGenerator(secureRandom); var primeMapper = new Rfc3526PrimeMapper(); var fieldMapper = new FieldToCurveNameMapper(); rsaKeyProvider = new RsaKeyProvider(asymmetricKeyPairGenerator); dsaKeyProvider = new DsaKeyProvider(asymmetricKeyPairGenerator); ecKeyProvider = new EcKeyProvider(asymmetricKeyPairGenerator, fieldMapper); elGamalKeyProvider = new ElGamalKeyProvider(asymmetricKeyPairGenerator, primeMapper); cipherTypeMapper = new OidToCipherTypeMapper(); keyInfoWrapper = new Mock <KeyInfoWrapper>(); SetupValidKeyInfo(); SetupValidKeyProvider(); pkcsEncryptionProvider = new KeyEncryptionProvider(configuration, secureRandom, keyProvider, new Pkcs12KeyEncryptionGenerator(), new AesKeyEncryptionGenerator()); rsaKeyPair = rsaKeyProvider.CreateKeyPair(2048); dsaKeyPair = dsaKeyProvider.CreateKeyPair(2048); ecKeyPair = ecKeyProvider.CreateKeyPair("secp384r1"); elGamalKeyPair = elGamalKeyProvider.CreateKeyPair(2048, true); }
public void SetupEcKeyProviderTest() { asymmetricKeyPairGenerator = new AsymmetricKeyPairGenerator(new SecureRandomGenerator()); keyProvider = new EcKeyProvider(asymmetricKeyPairGenerator, new FieldToCurveNameMapper()); keyPair = keyProvider.CreateKeyPair("brainpoolP384t1"); }
public void ShouldThrowExceptionWhenKeyPairIsNotCurve25519() { keyPair = ecKeyProvider.CreateKeyPair("P-256"); var exception = Assert.Throws <InvalidOperationException>(() => provider.GetAsOpenSshPrivateKey(keyPair, "foo")); Assert.AreEqual("Only curve25519 keypair can be formatted in OpenSSH private key format.", exception.Message); }
public void SetupEcPemFormattingProviderTest() { var asymmetricKeyPairGenerator = new AsymmetricKeyPairGenerator(new SecureRandomGenerator()); ecKeyProvider = new EcKeyProvider(asymmetricKeyPairGenerator, new FieldToCurveNameMapper()); provider = new EcPemFormattingProvider(ecKeyProvider); keyPair = ecKeyProvider.CreateKeyPair("P-256"); }
protected void SetupWithEcdsaKey() { keyPair = ecKeyProvider.CreateKeyPair("brainpoolp512t1"); var privateEcKey = keyPair.PrivateKey; privateKey = pkcs8PemFormatter.GetAsPem(privateEcKey); file.Setup(f => f.ReadAllBytes("private.pem")) .Returns(encoding.GetBytes(privateKey)); }
public void Setup() { var randomGenerator = new Mock <SecureRandomGenerator>(); randomGenerator.Setup(r => r.NextBytes(4)) .Returns(new byte[] { 1, 1, 1, 1 }); ecKeyProvider = new EcKeyProvider(new AsymmetricKeyPairGenerator(new SecureRandomGenerator()), new FieldToCurveNameMapper()); sshKeyProvider = new SshKeyProvider(new EncodingWrapper(), new Base64Wrapper(), null, null, ecKeyProvider, randomGenerator.Object); keyPair = ecKeyProvider.CreateKeyPair("curve25519"); provider = new SshFormattingProvider(sshKeyProvider, new EncodingWrapper(), new Ssh2ContentFormatter(), new OpenSshContentFormatter(), new Base64Wrapper()); string result = provider.GetAsOpenSshPrivateKey(keyPair, "key comment"); resultLines = result.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); }