示例#1
0
        public override bool VerifySignature(SignaturePacket SigPacket)
        {
            if (!base.VerifySignature(SigPacket))
            {
                return(false);
            }

            return(false);
        }
示例#2
0
        //public bool SeekPacket(int PacketIdx)
        //{
        //    Reset();

        //    while (ReadNextPacket() != null && PacketIdx != _PacketIndex) ;

        //    return (PacketIdx == _PacketIndex);
        //}

        //public byte[] ReadPacketBytes()
        //{
        //    // Todo fix for partial packets
        //    long len = _NextIdx - _Idx;
        //    long OldPos = _fs.Position;

        //    byte[] Buffer = new byte[len];
        //    _fs.Seek(_Idx, SeekOrigin.Begin);
        //    _fs.Read(Buffer, 0, (int)len);
        //    _fs.Seek(OldPos, SeekOrigin.Begin);

        //    return Buffer;

        //}




        private PGPPacket CreatePGPPacket(byte PacketTag)
        {
            PGPPacket PGPPacket;

            if (PacketTag == 1)
                PGPPacket = new PKEncSessionKeyPacket();
            else if (PacketTag == 2)
                PGPPacket = new SignaturePacket();
            else if (PacketTag == 3)
                PGPPacket = new SymEncSessionKeyPacket();
            else if (PacketTag == 4)
                PGPPacket = new OnePassSignaturePacket();
            else if (PacketTag == 5)
                PGPPacket = new SecretKeyPacket();
            else if (PacketTag == 6)
                PGPPacket = new PublicKeyPacket();
            else if (PacketTag == 7)
                PGPPacket = new SecretKeyPacket();
            else if (PacketTag == 8)
                PGPPacket = new CompressedDataPacket();
            else if (PacketTag == 9)
                PGPPacket = new SymEncDataPacket();
            else if (PacketTag == 10)
                PGPPacket = new MarkerPacket();
            else if (PacketTag == 11)
                PGPPacket = new LiteralDataPacket();
            else if (PacketTag == 12)
                PGPPacket = new TrustPacket();
            else if (PacketTag == 13)
                PGPPacket = new UserIDPacket();
            else if (PacketTag == 14)
                PGPPacket = new PublicKeyPacket();
            else if (PacketTag == 17)
                PGPPacket = new UserAttributePacket();
            else if (PacketTag == 18)
                PGPPacket = new SymEncIPDataPacket();
            else if (PacketTag == 19)
                PGPPacket = new MDCPacket();
            else
                PGPPacket = new UnknownPacket();

            Length = BytesRemaining;
            _PacketOffset = (int)( _fs.Position - _Idx);

            PGPPacket.Length = this.Length;
            PGPPacket.PacketTag = PacketTag;
            PGPPacket.PacketIndex = _PacketIndex;
            PGPPacket.FileName = this.FileName;

            return PGPPacket;
        }
示例#3
0
        public override bool VerifySignature(SignaturePacket SigPacket)
        {
            if (!base.VerifySignature(SigPacket))
            {
                return(false);
            }

            if (!(SigPacket.SecretKeyTransformedData is SecretKeyTransformedRSAData rsa))
            {
                return(false);
            }



            var           csp   = new RSACryptoServiceProvider(ModN.Length * 8);
            RSAParameters param = new RSAParameters
            {
                Modulus  = ModN,
                Exponent = Exp
            };

            byte[] SigVerify = new byte[ModN.Length];

            csp.ImportParameters(param);


            if (rsa.M_D_ModN.Length > ModN.Length)
            {
                return(false);
            }


            if (rsa.M_D_ModN.Length < ModN.Length)
            {
                Array.Copy(rsa.M_D_ModN, 0, SigVerify, ModN.Length - rsa.M_D_ModN.Length, rsa.M_D_ModN.Length);
            }
            else
            {
                Array.Copy(rsa.M_D_ModN, SigVerify, ModN.Length);
            }

            try
            {
                bool IsMatch = csp.VerifyHash(SigPacket.HashedData, SigVerify, SigPacket.HashAlgorithmName, RSASignaturePadding.Pkcs1);
                return(IsMatch);
            }
            catch { }

            return(false);
        }
示例#4
0
        public virtual bool VerifySignature(SignaturePacket SigPacket)
        {
            if (SigPacket.SecretKeyTransformedData == null)
            {
                return(false);
            }

            if (SigPacket.HashedData == null)
            {
                return(false);
            }

            return(true);
        }
示例#5
0
        public void GenerateCertifyHash(PublicKeyPacket PKP, UserIDPacket UIDP)
        {
            SignaturePacket SigP = this;

            int HashContextLength = 3 + PKP.PacketDataPublicKey.Length +
                                    5 + UIDP.UserIDBytes.Length +
                                    6 + SigP.HashedSubPacketBytes.Length
                                    + 6;

            int idx = 3 + PKP.PacketDataPublicKey.Length;

            byte[] HashContext = new byte[HashContextLength];

            HashContext[0] = 0x99;
            HashContext[1] = (byte)((PKP.PacketDataPublicKey.Length & 0xFF00) >> 8);
            HashContext[2] = (byte)(PKP.PacketDataPublicKey.Length & 0x00FF);
            Array.Copy(PKP.PacketDataPublicKey, 0, HashContext, 3, PKP.PacketDataPublicKey.Length);

            HashContext[idx++] = 0xB4;
            HashContext[idx++] = (byte)((UIDP.UserIDBytes.Length & 0xFF000000) >> 24);
            HashContext[idx++] = (byte)((UIDP.UserIDBytes.Length & 0x00FF0000) >> 16);
            HashContext[idx++] = (byte)((UIDP.UserIDBytes.Length & 0x0000FF00) >> 8);
            HashContext[idx++] = (byte)(UIDP.UserIDBytes.Length & 0x000000FF);
            Array.Copy(UIDP.UserIDBytes, 0, HashContext, idx, UIDP.UserIDBytes.Length);
            idx += UIDP.UserIDBytes.Length;

            HashContext[idx++] = SigP.Version;
            HashContext[idx++] = SigP.SignatureType;
            HashContext[idx++] = SigP.PKAlgo;
            HashContext[idx++] = SigP.HashAlgorithm;  // Version 4
            HashContext[idx++] = (byte)((SigP.HashedSubPacketBytes.Length & 0xFF00) >> 8);
            HashContext[idx++] = (byte)(SigP.HashedSubPacketBytes.Length & 0x00FF);
            Array.Copy(SigP.HashedSubPacketBytes, 0, HashContext, idx, SigP.HashedSubPacketBytes.Length);
            var HashedSubPacketLength = SigP.HashedSubPacketBytes.Length;

            idx += HashedSubPacketLength;

            HashContext[idx++] = 0x04;
            HashContext[idx++] = 0xFF;

            HashedSubPacketLength += 6; // Add the bytes before the hashed data

            HashContext[idx++] = (byte)((HashedSubPacketLength & 0xFF000000) >> 24);
            HashContext[idx++] = (byte)((HashedSubPacketLength & 0x00FF0000) >> 16);
            HashContext[idx++] = (byte)((HashedSubPacketLength & 0x0000FF00) >> 8);
            HashContext[idx++] = (byte)(HashedSubPacketLength & 0x000000FF);

            HashedData = ComputeHash(HashContext);
        }
示例#6
0
        public void GenerateSubKeyBindingHash(PublicKeyPacket PKP, PublicKeyPacket SubKey)
        {
            SignaturePacket SigP = this;

            int HashContextLength = 3 + PKP.PacketDataPublicKey.Length +
                                    3 + SubKey.PacketDataPublicKey.Length +
                                    6 + SigP.HashedSubPacketBytes.Length
                                    + 6;

            int idx = 0;

            byte[] HashContext = new byte[HashContextLength];

            HashContext[idx++] = 0x99;
            HashContext[idx++] = (byte)((PKP.PacketDataPublicKey.Length & 0xFF00) >> 8);
            HashContext[idx++] = (byte)(PKP.PacketDataPublicKey.Length & 0x00FF);
            Array.Copy(PKP.PacketDataPublicKey, 0, HashContext, idx, PKP.PacketDataPublicKey.Length);
            idx += PKP.PacketDataPublicKey.Length;

            HashContext[idx++] = 0x99;
            HashContext[idx++] = (byte)((SubKey.PacketDataPublicKey.Length & 0xFF00) >> 8);
            HashContext[idx++] = (byte)(SubKey.PacketDataPublicKey.Length & 0x00FF);
            Array.Copy(SubKey.PacketDataPublicKey, 0, HashContext, idx, SubKey.PacketDataPublicKey.Length);
            idx += SubKey.PacketDataPublicKey.Length;

            HashContext[idx++] = SigP.Version;
            HashContext[idx++] = SigP.SignatureType;
            HashContext[idx++] = SigP.PKAlgo;
            HashContext[idx++] = SigP.HashAlgorithm;  // Version 4
            HashContext[idx++] = (byte)((SigP.HashedSubPacketBytes.Length & 0xFF00) >> 8);
            HashContext[idx++] = (byte)(SigP.HashedSubPacketBytes.Length & 0x00FF);
            Array.Copy(SigP.HashedSubPacketBytes, 0, HashContext, idx, SigP.HashedSubPacketBytes.Length);
            var HashedSubPacketLength = SigP.HashedSubPacketBytes.Length;

            idx += HashedSubPacketLength;

            HashContext[idx++] = 0x04;
            HashContext[idx++] = 0xFF;

            HashedSubPacketLength += 6; // Add the bytes before the hashed data

            HashContext[idx++] = (byte)((HashedSubPacketLength & 0xFF000000) >> 24);
            HashContext[idx++] = (byte)((HashedSubPacketLength & 0x00FF0000) >> 16);
            HashContext[idx++] = (byte)((HashedSubPacketLength & 0x0000FF00) >> 8);
            HashContext[idx++] = (byte)(HashedSubPacketLength & 0x000000FF);

            HashedData = ComputeHash(HashContext);
        }
示例#7
0
文件: DSA.cs 项目: titasraha/opex
        public override bool VerifySignature(SignaturePacket SigPacket)
        {
            if (!base.VerifySignature(SigPacket))
            {
                return(false);
            }

            if (!(SigPacket.SecretKeyTransformedData is SecretKeyTransformedDSAData dsa))
            {
                return(false);
            }

            var           csp   = new DSACryptoServiceProvider();
            DSAParameters param = new DSAParameters
            {
                P = P,
                Q = Q,
                G = G,
                Y = Y
            };


            csp.ImportParameters(param);

            if (SigPacket.HashedData.Length < Q.Length)
            {
                return(false);
            }

            var SubHash = SigPacket.HashedData.SubArray(0, Q.Length);

            byte[] SigVerify = new byte[dsa.R.Length + dsa.S.Length];

            Array.Copy(dsa.R, 0, SigVerify, 0, dsa.R.Length);
            Array.Copy(dsa.S, 0, SigVerify, dsa.R.Length, dsa.S.Length);


            try
            {
                bool IsMatch = csp.VerifyHash(SubHash, SigPacket.HashAlgorithmName.Name, SigVerify);
                return(IsMatch);
            }
            catch { }

            return(false);
        }