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 VerifySignatureTestSetup() { file = new Mock <FileWrapper>(); file.Setup(f => f.ReadAllBytes(It.IsAny <string>())) .Returns <string>(givenFile => files[givenFile]); console = new Mock <ConsoleWrapper>(); Container container = ContainerProvider.GetContainer(); container.Register <FileWrapper>(() => file.Object); container.Register <ConsoleWrapper>(() => console.Object); var asymmetricKeyPairGenerator = new AsymmetricKeyPairGenerator(new SecureRandomGenerator()); var primeMapper = new Rfc3526PrimeMapper(); var curveNameMapper = new FieldToCurveNameMapper(); rsaKeyProvider = new RsaKeyProvider(asymmetricKeyPairGenerator); dsaKeyProvider = new DsaKeyProvider(asymmetricKeyPairGenerator); ecKeyProvider = new EcKeyProvider(asymmetricKeyPairGenerator, curveNameMapper); elGamalKeyProvider = new ElGamalKeyProvider(asymmetricKeyPairGenerator, primeMapper); signatureProvider = new SignatureProvider(new SignatureAlgorithmIdentifierMapper(), new SecureRandomGenerator(), new SignerUtilitiesWrapper()); pkcs8PemFormatter = new Pkcs8PemFormattingProvider(new AsymmetricKeyProvider(new OidToCipherTypeMapper(), new KeyInfoWrapper(), rsaKeyProvider, dsaKeyProvider, ecKeyProvider, elGamalKeyProvider)); base64 = new Base64Wrapper(); encoding = new EncodingWrapper(); random = new SecureRandomGenerator(); }
public void SetupEcKeyProviderTest() { asymmetricKeyPairGenerator = new AsymmetricKeyPairGenerator(new SecureRandomGenerator()); keyProvider = new EcKeyProvider(asymmetricKeyPairGenerator, new FieldToCurveNameMapper()); keyPair = keyProvider.CreateKeyPair("brainpoolP384t1"); }
public void SetupVerifyKeyPairTest() { var asymmetricKeyPairGenerator = new AsymmetricKeyPairGenerator(new SecureRandomGenerator()); var primeMapper = new Rfc3526PrimeMapper(); var curveNameMapper = new FieldToCurveNameMapper(); rsaKeyProvider = new RsaKeyProvider(asymmetricKeyPairGenerator); dsaKeyProvider = new DsaKeyProvider(asymmetricKeyPairGenerator); ecKeyProvider = new EcKeyProvider(asymmetricKeyPairGenerator, curveNameMapper); elGamalKeyProvider = new ElGamalKeyProvider(asymmetricKeyPairGenerator, primeMapper); encoding = new EncodingWrapper(); pkcs8PemFormatter = new Pkcs8PemFormattingProvider(new AsymmetricKeyProvider(new OidToCipherTypeMapper(), new KeyInfoWrapper(), rsaKeyProvider, dsaKeyProvider, ecKeyProvider, elGamalKeyProvider)); files = new Dictionary <string, byte[]>(); file = new Mock <FileWrapper>(); file.Setup(f => f.ReadAllBytes(It.IsAny <string>())) .Returns <string>(givenFile => files[givenFile]); console = new Mock <ConsoleWrapper>(); Container container = ContainerProvider.GetContainer(); container.Register <FileWrapper>(() => file.Object); container.Register <ConsoleWrapper>(() => console.Object); }
public void SetupRsaKeyProviderTest() { var secureRandomGenerator = new SecureRandomGenerator(); var asymmetricKeyGenerator = new AsymmetricKeyPairGenerator(secureRandomGenerator); keyProvider = new RsaKeyProvider(asymmetricKeyGenerator); }
public void Setup() { var asymmetricKeyPairGenerator = new AsymmetricKeyPairGenerator(new SecureRandomGenerator()); keyProvider = new EcKeyProvider(asymmetricKeyPairGenerator, new FieldToCurveNameMapper()); mapper = new FieldToCurveNameMapper(); }
public void SetupDsaKeyProviderTest() { var secureRandomGenerator = new SecureRandomGenerator(); var keyGenerator = new AsymmetricKeyPairGenerator(secureRandomGenerator); keyProvider = new DsaKeyProvider(keyGenerator); keyPair = keyProvider.CreateKeyPair(2048); }
public void SetupEcPemFormattingProviderTest() { var asymmetricKeyPairGenerator = new AsymmetricKeyPairGenerator(new SecureRandomGenerator()); ecKeyProvider = new EcKeyProvider(asymmetricKeyPairGenerator, new FieldToCurveNameMapper()); provider = new EcPemFormattingProvider(ecKeyProvider); keyPair = ecKeyProvider.CreateKeyPair("P-256"); }
public void SetupSshKeyProviderTest() { encoding = new EncodingWrapper(); keyPairGenerator = new AsymmetricKeyPairGenerator(new SecureRandomGenerator()); ecKeyProvider = new EcKeyProvider(keyPairGenerator, new FieldToCurveNameMapper()); provider = new SshKeyProvider(encoding, new Base64Wrapper(), Mock.Of <IRsaKeyProvider>(), Mock.Of <IDsaKeyProvider>(), ecKeyProvider, new SecureRandomGenerator()); base64 = new Base64Wrapper(); }
public void SetupGetKeyFromSsh() { var asymmetricKeyPairGenerator = new AsymmetricKeyPairGenerator(new SecureRandomGenerator()); rsaKeyProvider = new RsaKeyProvider(asymmetricKeyPairGenerator); dsaKeyProvider = new DsaKeyProvider(asymmetricKeyPairGenerator); provider = new SshKeyProvider(new EncodingWrapper(), new Base64Wrapper(), rsaKeyProvider, dsaKeyProvider, ecKeyProvider, null); }
public void SetupElGamalKeyProviderTest() { var secureRandomGenerator = new SecureRandomGenerator(); var keyGenerator = new AsymmetricKeyPairGenerator(secureRandomGenerator); var primeMapper = new Rfc3526PrimeMapper(); keyProvider = new ElGamalKeyProvider(keyGenerator, primeMapper); keyPair = keyProvider.CreateKeyPair(2048, true); }
public void SetupSignatureProviderTest() { algorithmIdentifierMapper = new SignatureAlgorithmIdentifierMapper(); secureRandomGenerator = new SecureRandomGenerator(); signatureProvider = new SignatureProvider(algorithmIdentifierMapper, secureRandomGenerator, new SignerUtilitiesWrapper()); content = secureRandomGenerator.NextBytes(2000); keys = new Dictionary <CipherType, IAsymmetricKeyPair>(); var rsaGenerator = new AsymmetricKeyPairGenerator(secureRandomGenerator); var rsaKeyProvider = new RsaKeyProvider(rsaGenerator); IAsymmetricKeyPair keyPair = rsaKeyProvider.CreateKeyPair(2048); keys.Add(keyPair.PrivateKey.CipherType, keyPair); }
public void SetupGetAsDer() { var secureRandom = new SecureRandomGenerator(); var asymmetricKeyPairGenerator = new AsymmetricKeyPairGenerator(secureRandom); var rsaKeyProvider = new RsaKeyProvider(asymmetricKeyPairGenerator); var dsaKeyProvider = new DsaKeyProvider(asymmetricKeyPairGenerator); var ecKeyProvier = new EcKeyProvider(asymmetricKeyPairGenerator, new FieldToCurveNameMapper()); var keyPair = rsaKeyProvider.CreateKeyPair(1024); var key = keyPair.PublicKey; var encoding = new EncodingWrapper(); var base64 = new Base64Wrapper(); var sshKeyProvider = new SshKeyProvider(encoding, base64, rsaKeyProvider, dsaKeyProvider, ecKeyProvier, null); var formattingProvider = new SshFormattingProvider(sshKeyProvider, encoding, new Ssh2ContentFormatter(), null, base64); ssh2Key = formattingProvider.GetAsSsh2PublicKey(key, "foo"); keyContent = sshKeyProvider.GetRsaPublicKeyContent(key); openSshKey = formattingProvider.GetAsOpenSshPublicKey(key, "foo"); }
public void SetupCreateSignatureTest() { encoding = new EncodingWrapper(); var random = new SecureRandomGenerator(); fileContent = random.NextBytes(10000); file = new Mock <FileWrapper>(); fileOutput = new Dictionary <string, byte[]>(); file.Setup(f => f.WriteAllBytes(It.IsAny <string>(), It.IsAny <byte[]>())) .Callback <string, byte[]>((path, content) => { fileOutput.Add(path, content); }); file.Setup(f => f.ReadAllBytes("foo.file")) .Returns(fileContent); console = new Mock <ConsoleWrapper>(); consoleOutput = new List <string>(); console.Setup(c => c.WriteLine(It.IsAny <string>())) .Callback <string>(input => consoleOutput.Add(input)); Container container = ContainerProvider.GetContainer(); container.Register <FileWrapper>(() => file.Object); container.Register <ConsoleWrapper>(() => console.Object); var asymmetricKeyPairGenerator = new AsymmetricKeyPairGenerator(new SecureRandomGenerator()); rsaKeyProvider = new RsaKeyProvider(asymmetricKeyPairGenerator); dsaKeyProvider = new DsaKeyProvider(asymmetricKeyPairGenerator); ecKeyProvider = new EcKeyProvider(asymmetricKeyPairGenerator, new FieldToCurveNameMapper()); var asymmetricKeyProvider = new AsymmetricKeyProvider(new OidToCipherTypeMapper(), new KeyInfoWrapper(), rsaKeyProvider, dsaKeyProvider, null, null); pkcs8PemFormatter = new Pkcs8PemFormattingProvider(asymmetricKeyProvider); }
public EcKeyProvider(AsymmetricKeyPairGenerator keyPairGenerator, FieldToCurveNameMapper curveNameMapper) { this.keyPairGenerator = keyPairGenerator; this.curveNameMapper = curveNameMapper; }
public void SetupRsaGeneratorTest() { var secureRandom = new SecureRandomGenerator(); asymmetricKeyPairGenerator = new AsymmetricKeyPairGenerator(secureRandom); }
public RsaKeyProvider(AsymmetricKeyPairGenerator asymmetricKeyPairGenerator) { this.asymmetricKeyPairGenerator = asymmetricKeyPairGenerator; }
public DsaKeyProvider(AsymmetricKeyPairGenerator keyGenerator) { this.keyGenerator = keyGenerator; }
public ElGamalKeyProvider(AsymmetricKeyPairGenerator keyPairGenerator, Rfc3526PrimeMapper primes) { this.keyPairGenerator = keyPairGenerator; this.primes = primes; }