Exemplo n.º 1
0
        public override ByteBlock GetPrivateByteBlocks()
        {
            ByteBlock Result = new ByteBlock();

            if (PrivateKeyDecrypted)
            {
                Result.AddChildBlock("RSA secret exponent d", D.Length.ToString() + " Bytes", 0, D);
                Result.AddChildBlock("RSA secret prime value p", P.Length.ToString() + " Bytes", 0, P);
                Result.AddChildBlock("RSA secret prime value q (p < q)", Q.Length.ToString() + " Bytes", 0, Q);
                Result.AddChildBlock("u, the multiplicative inverse of p, mod q", U.Length.ToString() + " Bytes", 0, U);
            }
            return(Result.ChildBlock);
        }
Exemplo n.º 2
0
        public override ByteBlock GetPrivateByteBlocks()
        {
            ByteBlock Result = new ByteBlock();

            if (PrivateKeyDecrypted)
            {
                Result.AddChildBlock("Elgamal secret exponent x", X.Length.ToString() + " Bytes", 0, X);
            }

            return(Result.ChildBlock);
        }
Exemplo n.º 3
0
        private void ExtractPrivateKey()
        {
            if (!PublicKeyAlgorithm.PrivateKeyDecrypted)
            {
                PinEntry frm    = new PinEntry();
                bool     Result = false;
                do
                {
                    if (frm.ShowDialog() == DialogResult.Cancel)
                    {
                        break;
                    }

                    Result = PublicKeyAlgorithm.DecryptS2K(frm.Password);
                } while (!Result);

                if (Result)
                {
                    SecretKeyNode.AddChildBlock(PublicKeyAlgorithm.GetPrivateByteBlocks());
                }
            }
        }
Exemplo n.º 4
0
        public static ByteBlock Process(string PGPFile)
        {
            var             Root = new ByteBlock();
            PGPPacket       pgp;
            PublicKeyPacket PrimaryKeyPacket = null;
            PublicKeyPacket SubKeyPacket     = null;
            UserIDPacket    UIDPacket        = null;
            Stack <OnePassSignaturePacket> OPSigPacketStack = new Stack <OnePassSignaturePacket>();

            HashAlgorithm[] HashAlgorithms = null;


            using (var PacketReader = new PGPReader(PGPFile))
            {
                PacketReader.DoIndexUpdate += IndexUpdate;
                while ((pgp = PacketReader.ReadNextPacket()) != null)
                {
                    TreeBuilder Tree = new TreeBuilder(PacketReader);
                    pgp.Parse(Tree);

                    if (pgp is LiteralDataPacket litPgp)
                    {
                        if (HashAlgorithms == null)
                        {
                            HashAlgorithms = GetHashAlgorithms(OPSigPacketStack);
                        }

                        litPgp.ProgressUpdate += StatusUpdate;
                        litPgp.DoHash(PacketReader, HashAlgorithms);
                    }
                    else
                    {
                        if (pgp is OnePassSignaturePacket OPSig)
                        {
                            OPSigPacketStack.Push(OPSig);
                        }
                        else if (pgp.PacketTag == 6 || pgp.PacketTag == 5)
                        {
                            PrimaryKeyPacket = (PublicKeyPacket)pgp;
                        }
                        else if (pgp is UserIDPacket)
                        {
                            UIDPacket = (UserIDPacket)pgp;
                        }
                        else if (pgp.PacketTag == 14 || pgp.PacketTag == 7)
                        {
                            SubKeyPacket = (PublicKeyPacket)pgp;
                        }
                        else if (pgp is SignaturePacket Sig)
                        {
                            if ((Sig.SignatureType == 0x18 || Sig.SignatureType == 0x19) && PrimaryKeyPacket != null && SubKeyPacket != null && SubKeyPacket.PacketDataPublicKey != null)
                            {
                                Sig.GenerateSubKeyBindingHash(PrimaryKeyPacket, SubKeyPacket);
                            }

                            if (Sig.SignatureType >= 0x10 && Sig.SignatureType <= 0x13 && PrimaryKeyPacket != null && UIDPacket != null)
                            {
                                Sig.GenerateCertifyHash(PrimaryKeyPacket, UIDPacket);
                            }

                            // Signature of a Binary Document
                            if (Sig.SignatureType == 0x00)
                            {
                                // Are we generating hash for One Pass Signature Packet
                                if (OPSigPacketStack.Count() > 0)
                                {
                                    var OnePassSignaturePacket = OPSigPacketStack.Pop();

                                    if (OnePassSignaturePacket.HashAlgorithm == Sig.HashAlgorithm)
                                    {
                                        Sig.GenerateBinaryHash(HashAlgorithmTypes.GetHashAlgoManaged(Sig.HashAlgorithm, HashAlgorithms));
                                    }
                                }
                            }
                        }
                    }


                    PacketBlock pb = new PacketBlock(pgp);
                    pb.AddChildBlock(Tree.StartBlock);
                    Root.AddChildBlock(pb);

                    _PacketNodes.Add(pb);
                }
            }

            return(Root.ChildBlock);
        }