public Boolean Decreypt(string encrypt, int ID)
        {
            //Get Public File
            GetKey  objKey     = new GetKey();
            DataRow drKey      = objKey.drSearchStudentKey(ID);
            string  PublicKey1 = drKey[0].ToString();

            // obtain an OpenPGP signed message
            String signedString = encrypt;

            // Extract the message and check the validity of the signature
            String plainText;

            // create an instance of the library
            PGPLib pgp = new PGPLib();
            SignatureCheckResult signatureCheck;

            try
            {
                signatureCheck = pgp.VerifyString(signedString,
                                                  new FileInfo(PublicKey1), out plainText);
            }
            catch
            {
                return(false);
            }



            string strData1 = plainText;

            // Print the results
            Console.WriteLine("Extracted plain text message is " + plainText);
            if (signatureCheck == SignatureCheckResult.SignatureVerified)
            {
                // Console.WriteLine("Signature OK");
                return(true);
            }
            else if (signatureCheck == SignatureCheckResult.SignatureBroken)
            {
                //Console.WriteLine("Signature of the message is either broken or forged");
                return(false);
            }
            else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching)
            {
                //   Console.WriteLine("The provided public key doesn't match the signature");
                return(false);
            }
            else if (signatureCheck == SignatureCheckResult.NoSignatureFound)
            {
                //  Console.WriteLine("This message is not digitally signed");
                return(false);
            }
            return(false);
        }
Beispiel #2
0
        public void Decreypt(string encrypt)
        {
            //Get Public File
            GetKey  objKey     = new GetKey();
            int     ID         = Convert.ToInt32(Session["ID"].ToString());
            DataRow drKey      = objKey.drSearchStudentKey(ID);
            string  PublicKey1 = drKey[0].ToString();



            // obtain an OpenPGP signed message
            String signedString = encrypt;

            // Extract the message and check the validity of the signature
            String plainText;

            // create an instance of the library
            PGPLib pgp = new PGPLib();

            //SignatureCheckResult signatureCheck = pgp.VerifyString(signedString,
            //                                        new FileInfo(@"C:\Users\Dua'a-Orcas\Desktop\finalProject\WebApplication1 - Copy (2)\WebApplication1\Sig\public_key_exported.asc"),
            //                                        out plainText);


            SignatureCheckResult signatureCheck = pgp.VerifyString(signedString,
                                                                   new FileInfo(PublicKey1), out plainText);


            string strData1 = plainText;

            // Print the results
            Console.WriteLine("Extracted plain text message is " + plainText);
            if (signatureCheck == SignatureCheckResult.SignatureVerified)
            {
                Console.WriteLine("Signature OK");
                Result = true;
            }
            else if (signatureCheck == SignatureCheckResult.SignatureBroken)
            {
                Console.WriteLine("Signature of the message is either broken or forged");
            }
            else if (signatureCheck == SignatureCheckResult.PublicKeyNotMatching)
            {
                Console.WriteLine("The provided public key doesn't match the signature");
            }
            else if (signatureCheck == SignatureCheckResult.NoSignatureFound)
            {
                Console.WriteLine("This message is not digitally signed");
            }
        }