Formats SSH private keys in PEM format.
Наследование: KeyFormatter
Пример #1
0
 public void TestDeserializeDsaFromPrivate()
 {
     var formatter = new PemKeyFormatter();
     var key = formatter.Deserialize(Resources.dsa_1);
     Assert.That(key.Version, Is.EqualTo(SshVersion.SSH2));
     Assert.That(key.Algorithm, Is.EqualTo(PublicKeyAlgorithm.SSH_DSS));
     var publicKey = (DsaPublicKeyParameters)key.GetPublicKeyParameters();
     var privateKey = (DsaPrivateKeyParameters)key.GetPrivateKeyParameters();
     var param_g = new BigInteger(Resources.dsa_1_param_g.Trim(), 16);
     var param_priv = new BigInteger(Resources.dsa_1_param_priv.Trim(), 16);
     var param_pub = new BigInteger(Resources.dsa_1_param_pub.Trim(), 16);
     Assert.That(privateKey.Parameters.G, Is.EqualTo(param_g));
     Assert.That(privateKey.X, Is.EqualTo(param_priv));
     Assert.That(publicKey.Y, Is.EqualTo(param_pub));
 }
Пример #2
0
 public void TestDeserializeRsaFromNewForamt()
 {
     // This is actaully exactly the same as TestDeserializeRsaFromPrivate
     var formatter = new PemKeyFormatter();
     var key = formatter.Deserialize(Resources.rsa_n);
     Assert.That(key.Version, Is.EqualTo(SshVersion.SSH2));
     Assert.That(key.Algorithm, Is.EqualTo(PublicKeyAlgorithm.SSH_RSA));
     var publicKey = (RsaKeyParameters)key.GetPublicKeyParameters();
     var privateKey = (RsaPrivateCrtKeyParameters)key.GetPrivateKeyParameters();
     var param_n = new BigInteger(Resources.rsa_1_param_n.Trim(), 16);
     var param_p = new BigInteger(Resources.rsa_1_param_p.Trim(), 16);
     var param_q = new BigInteger(Resources.rsa_1_param_q.Trim(), 16);
     Assert.That(publicKey.Modulus, Is.EqualTo(param_n));
     Assert.That(privateKey.P, Is.EqualTo(param_p));
     Assert.That(privateKey.Q, Is.EqualTo(param_q));
 }
Пример #3
0
 public void TestDeserializeEcdsaFromNewForamt()
 {
     // This is actaully exactly the same as TestDeserializeEcdsaFromPrivate
     var formatter = new PemKeyFormatter();
     var key = formatter.Deserialize(Resources.ecdsa_n);
     Assert.That(key.Version, Is.EqualTo(SshVersion.SSH2));
     Assert.That(key.Algorithm, Is.EqualTo(PublicKeyAlgorithm.ECDSA_SHA2_NISTP256));
     var publicKey = (ECPublicKeyParameters)key.GetPublicKeyParameters();
     var privateKey = (ECPrivateKeyParameters)key.GetPrivateKeyParameters();
     var param_curve = X962NamedCurves.GetByName(Resources.ecdsa_1_param_curve.Trim());
     var param_priv = new BigInteger(Resources.ecdsa_1_param_priv.Trim(), 16);
     var param_pub = new BigInteger(Resources.ecdsa_1_param_pub.Trim(), 16);
     Assert.That(privateKey.Parameters.Curve, Is.EqualTo(param_curve.Curve));
     Assert.That(privateKey.D, Is.EqualTo(param_priv));
     // TODO: figure out how to convert public key to BigInteger that matches param_pub
     //Assert.That(publicKey.Q, Is.EqualTo(param_pub));
 }
Пример #4
0
 public void TestDeserializeRsaFromPrivateWithPassphrase()
 {
     var formatter = new PemKeyFormatter();
     formatter.GetPassphraseCallbackMethod = passphraseCallback;
     var key = formatter.Deserialize(Resources.rsa_1_pw);
     Assert.That(key.Version, Is.EqualTo(SshVersion.SSH2));
     Assert.That(key.Algorithm, Is.EqualTo(PublicKeyAlgorithm.SSH_RSA));
     var publicKey = (RsaKeyParameters)key.GetPublicKeyParameters();
     var privateKey = (RsaPrivateCrtKeyParameters)key.GetPrivateKeyParameters();
     var param_n = new BigInteger(Resources.rsa_1_param_n.Trim(), 16);
     var param_p = new BigInteger(Resources.rsa_1_param_p.Trim(), 16);
     var param_q = new BigInteger(Resources.rsa_1_param_q.Trim(), 16);
     Assert.That(publicKey.Modulus, Is.EqualTo(param_n));
     Assert.That(privateKey.P, Is.EqualTo(param_p));
     Assert.That(privateKey.Q, Is.EqualTo(param_q));
 }