コード例 #1
0
                public void PublicKeyIsEmpty()
                {
                    DsaPublicKeyParameters keyParameters = (DsaPublicKeyParameters)PublicKeyFactory.CreateKey(keyPair.PublicKey.Content);
                    DsaKey publicKey = GetModifiedPublicKey(BigInteger.Zero, keyParameters.Parameters.G, keyParameters.Parameters.P, keyParameters.Parameters.Q);

                    Assert.IsFalse(keyProvider.VerifyKeyPair(new AsymmetricKeyPair(keyPair.PrivateKey, publicKey)));
                }
コード例 #2
0
ファイル: DsaKeyTest.cs プロジェクト: lrdcasimir/ssh.net
        public void DisposeTest()
        {
            DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value

            target.Dispose();
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
コード例 #3
0
ファイル: DsaKeyTest.cs プロジェクト: lrdcasimir/ssh.net
        [Ignore] // placeholder for actual test
        public void DsaKeyConstructorTest1()
        {
            byte[] data   = null; // TODO: Initialize to an appropriate value
            DsaKey target = new DsaKey(data);

            Assert.Inconclusive("TODO: Implement code to verify target");
        }
コード例 #4
0
        public void DsaDigitalSignatureConstructorTest()
        {
            DsaKey key = null; // TODO: Initialize to an appropriate value
            DsaDigitalSignature target = new DsaDigitalSignature(key);

            Assert.Inconclusive("TODO: Implement code to verify target");
        }
コード例 #5
0
ファイル: PgpKey.cs プロジェクト: 1hub/springburg
        /// <summary>The public key contained in the object.</summary>
        /// <returns>A lightweight public key.</returns>
        /// <exception cref="PgpException">If the key algorithm is not recognised.</exception>
        private IAsymmetricPublicKey GetKey()
        {
            if (key != null)
            {
                return(key);
            }

            switch (keyPacket.Algorithm)
            {
            case PgpPublicKeyAlgorithm.RsaEncrypt:
            case PgpPublicKeyAlgorithm.RsaGeneral:
            case PgpPublicKeyAlgorithm.RsaSign:
                return(key = RsaKey.CreatePublic(keyPacket.KeyBytes, out var _));

            case PgpPublicKeyAlgorithm.Dsa:
                return(key = DsaKey.CreatePublic(keyPacket.KeyBytes, out var _));

            case PgpPublicKeyAlgorithm.ElGamalEncrypt:
            case PgpPublicKeyAlgorithm.ElGamalGeneral:
                return(key = ElGamalKey.CreatePublic(keyPacket.KeyBytes, out var _));

            case PgpPublicKeyAlgorithm.ECDsa:
                return(key = ECDsaKey.CreatePublic(keyPacket.KeyBytes, out var _));

            case PgpPublicKeyAlgorithm.ECDH:
                return(key = ECDiffieHellmanKey.CreatePublic(fingerprint, keyPacket.KeyBytes, out var _));

            case PgpPublicKeyAlgorithm.EdDsa:
                return(key = EdDsaKey.CreatePublic(keyPacket.KeyBytes, out var _));

            default:
                throw new PgpException("unknown public key algorithm encountered");
            }
        }
コード例 #6
0
                public void DomainParameterPAreNotEqual()
                {
                    DsaPublicKeyParameters keyParameters = (DsaPublicKeyParameters)PublicKeyFactory.CreateKey(keyPair.PublicKey.Content);
                    DsaKey publicKey = GetModifiedPublicKey(keyParameters.Y, keyParameters.Parameters.G, keyParameters.Parameters.P.Add(BigInteger.One), keyParameters.Parameters.Q);

                    Assert.IsFalse(keyProvider.VerifyKeyPair(new AsymmetricKeyPair(keyPair.PrivateKey, publicKey)));
                }
コード例 #7
0
ファイル: DsaKeyTest.cs プロジェクト: lrdcasimir/ssh.net
        public void KeyLengthTest()
        {
            DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value
            int    actual;

            actual = target.KeyLength;
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
コード例 #8
0
ファイル: DsaKeyTest.cs プロジェクト: lrdcasimir/ssh.net
        public void PTest()
        {
            DsaKey     target = new DsaKey(); // TODO: Initialize to an appropriate value
            BigInteger actual;

            actual = target.P;
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
コード例 #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DsaDigitalSignature"/> class.
        /// </summary>
        /// <param name="key">The DSA key.</param>
        public DsaDigitalSignature(DsaKey key)
        {
            if (key == null)
                throw new ArgumentNullException("key");

            this._key = key;

            this._hash = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha1).CreateHash();
        }
コード例 #10
0
ファイル: DsaDigitalSignature.cs プロジェクト: sshnet/SSH.NET
        /// <summary>
        /// Initializes a new instance of the <see cref="DsaDigitalSignature" /> class.
        /// </summary>
        /// <param name="key">The DSA key.</param>
        /// <exception cref="ArgumentNullException"><paramref name="key"/> is <c>null</c>.</exception>
        public DsaDigitalSignature(DsaKey key)
        {
            if (key == null)
                throw new ArgumentNullException("key");

            _key = key;

            _hash = CryptoAbstraction.CreateSHA1();
        }
コード例 #11
0
ファイル: PgpKeyPair.cs プロジェクト: 1hub/springburg
        public PgpKeyPair(
            AsymmetricAlgorithm asymmetricAlgorithm,
            DateTime creationTime,
            bool isMasterKey = true)
        {
            IAsymmetricPrivateKey privateKey;
            IAsymmetricPublicKey  publicKey;

            byte[]? ecdhFingerprint = null;

            if (asymmetricAlgorithm is RSA rsa)
            {
                privateKey = new RsaKey(rsa);
            }
            else if (asymmetricAlgorithm is DSA dsa)
            {
                privateKey = new DsaKey(dsa);
            }
            else if (asymmetricAlgorithm is ElGamal elGamal)
            {
                privateKey = new ElGamalKey(elGamal);
            }
            else if (asymmetricAlgorithm is ECDiffieHellman ecdh)
            {
                privateKey = new ECDiffieHellmanKey(ecdh, new byte[] { 0, (byte)PgpHashAlgorithm.Sha256, (byte)PgpSymmetricKeyAlgorithm.Aes128 }, ecdhFingerprint = new byte[20]);
            }
            else if (asymmetricAlgorithm is Ed25519 eddsa)
            {
                privateKey = new EdDsaKey(eddsa);
            }
            else if (asymmetricAlgorithm is ECDsa ecdsa)
            {
                privateKey = new ECDsaKey(ecdsa);
            }
            else
            {
                throw new NotSupportedException();
            }
            publicKey = (IAsymmetricPublicKey)privateKey;

            var keyBytes  = publicKey.ExportPublicKey();
            var keyPacket = isMasterKey ?
                            new PublicKeyPacket(publicKey.Algorithm, creationTime, keyBytes) :
                            new PublicSubkeyPacket(publicKey.Algorithm, creationTime, keyBytes);

            this.PublicKey = new PgpPublicKey(keyPacket)
            {
                key = publicKey
            };

            if (ecdhFingerprint != null)
            {
                this.PublicKey.Fingerprint.Slice(0, 20).CopyTo(ecdhFingerprint);
            }

            this.PrivateKey = new PgpPrivateKey(this.PublicKey.KeyId, privateKey);
        }
コード例 #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DsaDigitalSignature" /> class.
        /// </summary>
        /// <param name="key">The DSA key.</param>
        /// <exception cref="System.ArgumentNullException">key</exception>
        public DsaDigitalSignature(DsaKey key)
        {
            if (key == null)
                throw new ArgumentNullException("key");

            this._key = key;

            this._hash = new SHA1Hash();
        }
コード例 #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DsaDigitalSignature" /> class.
        /// </summary>
        /// <param name="key">The DSA key.</param>
        /// <exception cref="ArgumentNullException"><paramref name="key"/> is <c>null</c>.</exception>
        public DsaDigitalSignature(DsaKey key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            _key = key;

            _hash = CryptoAbstraction.CreateSHA1();
        }
コード例 #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DsaDigitalSignature" /> class.
        /// </summary>
        /// <param name="key">The DSA key.</param>
        /// <exception cref="System.ArgumentNullException">key</exception>
        public DsaDigitalSignature(DsaKey key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            this._key = key;

            this._hash = new SHA1Hash();
        }
コード例 #15
0
ファイル: DsaKeyTest.cs プロジェクト: lrdcasimir/ssh.net
        public void DsaKeyConstructorTest2()
        {
            BigInteger p      = new BigInteger(); // TODO: Initialize to an appropriate value
            BigInteger q      = new BigInteger(); // TODO: Initialize to an appropriate value
            BigInteger g      = new BigInteger(); // TODO: Initialize to an appropriate value
            BigInteger y      = new BigInteger(); // TODO: Initialize to an appropriate value
            BigInteger x      = new BigInteger(); // TODO: Initialize to an appropriate value
            DsaKey     target = new DsaKey(p, q, g, y, x);

            Assert.Inconclusive("TODO: Implement code to verify target");
        }
コード例 #16
0
ファイル: DsaKeyTest.cs プロジェクト: lrdcasimir/ssh.net
        [Ignore] // placeholder for actual test
        public void PublicTest()
        {
            DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value

            BigInteger[] expected = null; // TODO: Initialize to an appropriate value
            BigInteger[] actual;
            target.Public = expected;
            actual        = target.Public;
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
コード例 #17
0
        public void SignTest()
        {
            DsaKey key = null;                                         // TODO: Initialize to an appropriate value
            DsaDigitalSignature target = new DsaDigitalSignature(key); // TODO: Initialize to an appropriate value

            byte[] input    = null;                                    // TODO: Initialize to an appropriate value
            byte[] expected = null;                                    // TODO: Initialize to an appropriate value
            byte[] actual;
            actual = target.Sign(input);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
コード例 #18
0
        public IAsymmetricKeyPair CreateKeyPair(int keySize)
        {
            AsymmetricCipherKeyPair keyPair = keyGenerator.GenerateDsaKeyPair(keySize);

            byte[] publicKeyContent  = GetPublicKey(keyPair.Public);
            byte[] privateKeyContent = GetPrivateKey(keyPair.Private);

            var publicKey  = new DsaKey(publicKeyContent, AsymmetricKeyType.Public, GetKeyLength(keyPair.Public));
            var privateKey = new DsaKey(privateKeyContent, AsymmetricKeyType.Private, GetKeyLength(keyPair.Private));

            return(new AsymmetricKeyPair(privateKey, publicKey));
        }
コード例 #19
0
                private IAsymmetricKey GetModifiedPrivateKey(BigInteger X, DsaParameters domainParameters)
                {
                    var modifiedPrivateKey = new DsaPrivateKeyParameters(X, domainParameters);

                    byte[] privateKeyContent = PrivateKeyInfoFactory.CreatePrivateKeyInfo(modifiedPrivateKey)
                                               .ToAsn1Object()
                                               .GetDerEncoded();

                    var privateKey = new DsaKey(privateKeyContent, AsymmetricKeyType.Private, modifiedPrivateKey.Parameters.P.BitLength);

                    return(privateKey);
                }
コード例 #20
0
                private DsaKey GetModifiedPublicKey(BigInteger Y, BigInteger G, BigInteger P, BigInteger Q)
                {
                    var modifiedParameters = new DsaParameters(P, Q, G);

                    var keyParameters = new DsaPublicKeyParameters(Y, modifiedParameters);

                    byte[] publicKeyContent = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(keyParameters)
                                              .ToAsn1Object()
                                              .GetDerEncoded();

                    var publicKey = new DsaKey(publicKeyContent, AsymmetricKeyType.Public, keyParameters.Parameters.P.BitLength);

                    return(publicKey);
                }
コード例 #21
0
        /// <summary>Extract a <c>PgpPrivateKey</c> from this secret key's encrypted contents.</summary>
        /// <remarks>
        /// Allows the caller to handle the encoding of the passphrase to bytes.
        /// </remarks>
        public PgpPrivateKey?ExtractPrivateKey(ReadOnlySpan <byte> rawPassPhrase)
        {
            if (IsPrivateKeyEmpty)
            {
                return(null);
            }

            if (keyPacket.Version < 4)
            {
                Debug.Assert(keyPacket.Algorithm == PgpPublicKeyAlgorithm.RsaGeneral || keyPacket.Algorithm == PgpPublicKeyAlgorithm.RsaEncrypt || keyPacket.Algorithm == PgpPublicKeyAlgorithm.RsaSign);
                var rsa = RsaKey.CreatePrivate(rawPassPhrase, keyPacket.KeyBytes, out var _, version: 3);
                return(new PgpPrivateKey(KeyId, rsa));
            }
            else if (keyPacket.Version >= 4)
            {
                switch (keyPacket.Algorithm)
                {
                case PgpPublicKeyAlgorithm.RsaGeneral:
                case PgpPublicKeyAlgorithm.RsaSign:
                case PgpPublicKeyAlgorithm.RsaEncrypt:
                    var rsa = RsaKey.CreatePrivate(rawPassPhrase, keyPacket.KeyBytes, out var _);
                    return(new PgpPrivateKey(KeyId, rsa));

                case PgpPublicKeyAlgorithm.Dsa:
                    var dsa = DsaKey.CreatePrivate(rawPassPhrase, keyPacket.KeyBytes, out var _);
                    return(new PgpPrivateKey(KeyId, dsa));

                case PgpPublicKeyAlgorithm.ECDH:
                    var ecdh = ECDiffieHellmanKey.CreatePrivate(Fingerprint, rawPassPhrase, keyPacket.KeyBytes, out var _);
                    return(new PgpPrivateKey(KeyId, ecdh));

                case PgpPublicKeyAlgorithm.ECDsa:
                    var ecdsa = ECDsaKey.CreatePrivate(rawPassPhrase, keyPacket.KeyBytes, out var _);
                    return(new PgpPrivateKey(KeyId, ecdsa));

                case PgpPublicKeyAlgorithm.EdDsa:
                    var eddsa = EdDsaKey.CreatePrivate(rawPassPhrase, keyPacket.KeyBytes, out var _);
                    return(new PgpPrivateKey(KeyId, eddsa));

                case PgpPublicKeyAlgorithm.ElGamalEncrypt:
                case PgpPublicKeyAlgorithm.ElGamalGeneral:
                    var elgamal = ElGamalKey.CreatePrivate(rawPassPhrase, keyPacket.KeyBytes, out var _);
                    return(new PgpPrivateKey(KeyId, elgamal));
                }
            }

            throw new PgpException("unknown public key version encountered");
        }
コード例 #22
0
 public static IDSA Create(DsaKey key) => new DsaFunction(key);
コード例 #23
0
ファイル: DsaKeyTest.cs プロジェクト: lrdcasimir/ssh.net
        public void DsaKeyConstructorTest()
        {
            DsaKey target = new DsaKey();

            Assert.Inconclusive("TODO: Implement code to verify target");
        }