Esempio n. 1
0
        /// <summary>
        /// Secret key operation. Decrypts biCipher with the keydata
        /// in the given secret key packet.
        /// </summary>
        /// <param name="biInput">The ciphertext that is about to
        /// be decrypted</param>
        /// <param name="skpKey">The secret key packet with the key
        /// material for the decryption</param>
        /// <param name="strPassphrase">The passphrase for the 
        /// keymaterial</param>
        /// <returns>The decrypted ciphertext.</returns>
        /// <remarks>No remarks.</remarks>
        public override BigInteger Decrypt(BigInteger[] biInput, SecretKeyPacket skpKey, string strPassphrase)
        {
            BigInteger[] biKeyMaterial = skpKey.GetDecryptedKeyMaterial(strPassphrase);
            EG_Secret_Key eskKey = new EG_Secret_Key();
            eskKey.x = biKeyMaterial[0];
            eskKey.p = skpKey.PublicKey.KeyMaterial[0];
            eskKey.g = skpKey.PublicKey.KeyMaterial[1];
            eskKey.y = skpKey.PublicKey.KeyMaterial[2];

            if (biInput.Length != 2)
                throw new ArgumentException("biInput is not an ElGamal encrypted Packet");

            BigInteger B = biInput[0];
            BigInteger c = biInput[1];

            BigInteger z = B.modPow(eskKey.x, eskKey.p).modInverse(eskKey.p);

            BigInteger output = (z * c) % eskKey.p;

            return output;
        }
Esempio n. 2
0
        private DSA_Secret_Key ParseSecretKey(SecretKeyPacket skpKey, string strPassphrase)
        {
            DSA_Secret_Key dskKey = new DSA_Secret_Key();

            dskKey.p = skpKey.PublicKey.KeyMaterial[0];
            dskKey.q = skpKey.PublicKey.KeyMaterial[1];
            dskKey.g = skpKey.PublicKey.KeyMaterial[2];
            dskKey.y = skpKey.PublicKey.KeyMaterial[3];

            BigInteger[] biSecretKeyMaterial = skpKey.GetDecryptedKeyMaterial(strPassphrase);

            dskKey.x = biSecretKeyMaterial[0];

            return dskKey;
        }
Esempio n. 3
0
        private RSA_Secret_Key ParseSecretKey(SecretKeyPacket skpKey, string strPassphrase)
        {
            RSA_Secret_Key rskKey = new RSA_Secret_Key();

            rskKey.n = skpKey.PublicKey.KeyMaterial[0];
            rskKey.e = skpKey.PublicKey.KeyMaterial[1];

            BigInteger[] biSecretKeyMaterial = skpKey.GetDecryptedKeyMaterial(strPassphrase);

            rskKey.d = biSecretKeyMaterial[0];
            rskKey.p = biSecretKeyMaterial[1];
            rskKey.q = biSecretKeyMaterial[2];
            rskKey.u = biSecretKeyMaterial[3];

            return rskKey;
        }