Example #1
0
        public string SignText(string strMessage, ulong lSignatureKeyID, string strPassphrase)
        {
            SignaturePacket spSign = new SignaturePacket();

            strMessage = Radix64.TrimMessage(strMessage);

            TransportableSecretKey tskKey = skrKeyRing.Find(lSignatureKeyID);
            SecretKeyPacket        skpKey = tskKey.FindKey(AsymActions.Sign);

            spSign.HashAlgorithm      = HashAlgorithms.SHA1;
            spSign.Format             = PacketFormats.New;
            spSign.KeyID              = skpKey.PublicKey.KeyID;
            spSign.TimeCreated        = DateTime.Now;
            spSign.SignatureAlgorithm = skpKey.PublicKey.Algorithm;
            spSign.SignatureType      = SignatureTypes.TextSignature;
            spSign.Version            = SignaturePacketVersionNumbers.v4;

            byte[] bMessage = System.Text.Encoding.UTF8.GetBytes(strMessage);
            spSign.Sign(bMessage, skpKey, strPassphrase);
            byte[] bSignature   = spSign.Generate();
            string strSignature = Radix64.Encode(bSignature, true);
            string strFinal     = Armor.WrapCleartextSignature(strMessage, strSignature);

            return(strFinal);
        }
Example #2
0
        public static string ClearTextSign(string strMessage, SecretKeyRing skrKeyRing)
        {
            SignaturePacket spSign = new SignaturePacket();

            strMessage = Radix64.TrimMessage(strMessage);
            QueryPassphrase qpPassphrase = new QueryPassphrase();

            qpPassphrase.ShowMyDialog(skrKeyRing);
            string strPassphrase          = qpPassphrase.Passphrase;
            TransportableSecretKey tskKey = qpPassphrase.SelectedKey;
            SecretKeyPacket        skpKey = tskKey.FindKey(AsymActions.Sign);

            Working wWorking = new Working();

            wWorking.Show();

            spSign.HashAlgorithm = HashAlgorithms.SHA1;
            spSign.Format        = PacketFormats.New;

            wWorking.Progress(10);

            SignatureSubPacket sspCreator = new SignatureSubPacket();

            sspCreator.Type  = SignatureSubPacketTypes.IssuerKeyID;
            sspCreator.KeyID = skpKey.PublicKey.KeyID;
            SignatureSubPacket sspCreationTime = new SignatureSubPacket();

            sspCreationTime.Type        = SignatureSubPacketTypes.SignatureCreationTime;
            sspCreationTime.TimeCreated = DateTime.Now;
            spSign.HashedSubPackets     = new SignatureSubPacket[2];
            spSign.HashedSubPackets[0]  = sspCreator;
            spSign.HashedSubPackets[1]  = sspCreationTime;

            wWorking.Progress(20);

            //spSign.KeyID = skpKey.PublicKey.KeyID;
            //spSign.TimeCreated = DateTime.Now;
            spSign.SignatureAlgorithm = skpKey.PublicKey.Algorithm;
            spSign.SignatureType      = SignatureTypes.TextSignature;
            spSign.Version            = SignaturePacketVersionNumbers.v4;

            wWorking.Progress(10);

            byte[] bMessage = System.Text.Encoding.UTF8.GetBytes(strMessage);
            spSign.Sign(bMessage, skpKey, strPassphrase);

            wWorking.Progress(40);
            byte[] bSignature = spSign.Generate();

            string strSignature = Radix64.Encode(bSignature, true);

            wWorking.Progress(20);

            string strFinal = Armor.WrapCleartextSignature(strMessage, strSignature);

            wWorking.Hide();

            return(strFinal);
        }
Example #3
0
        /// <summary>
        /// Gets the OpenPGP encoded representation of the signed
        /// message.
        /// </summary>
        /// <returns>Returns a byte array that contains the binary
        /// representation of the signed message.</returns>
        /// <remarks>No remarks</remarks>
        public override byte[] GetEncoded()
        {
            byte[] bSignedMessage = lmSignedMessage.GetEncoded();
            byte[] bSignature     = spSignature.Generate();

            byte[] bReturn = new byte[0];
            if (bOnePassSigned)
            {
                byte[] bOnePass = opsOnePass.Generate();
                bReturn = new byte[bSignedMessage.Length + bSignature.Length + bOnePass.Length];
                bOnePass.CopyTo(bReturn, 0);
                bSignedMessage.CopyTo(bReturn, bOnePass.Length);
                bSignature.CopyTo(bReturn, bOnePass.Length + bSignedMessage.Length);
            }
            else
            {
                bReturn = new byte[bSignedMessage.Length + bSignature.Length];
                bSignature.CopyTo(bReturn, 0);
                bSignedMessage.CopyTo(bReturn, bSignature.Length);
            }

            return(bReturn);
        }
        public static string ClearTextSign(string strMessage, SecretKeyRing skrKeyRing)
        {
            SignaturePacket spSign = new SignaturePacket();

            strMessage = Radix64.TrimMessage(strMessage);
            QueryPassphrase qpPassphrase = new QueryPassphrase();
            qpPassphrase.ShowMyDialog(skrKeyRing);
            string strPassphrase = qpPassphrase.Passphrase;
            TransportableSecretKey tskKey = qpPassphrase.SelectedKey;
            SecretKeyPacket skpKey = tskKey.FindKey(AsymActions.Sign);

            Working wWorking = new Working();
            wWorking.Show();

            spSign.HashAlgorithm = HashAlgorithms.SHA1;
            spSign.Format = PacketFormats.New;

            wWorking.Progress(10);

            SignatureSubPacket sspCreator = new SignatureSubPacket();
            sspCreator.Type = SignatureSubPacketTypes.IssuerKeyID;
            sspCreator.KeyID = skpKey.PublicKey.KeyID;
            SignatureSubPacket sspCreationTime = new SignatureSubPacket();
            sspCreationTime.Type = SignatureSubPacketTypes.SignatureCreationTime;
            sspCreationTime.TimeCreated = DateTime.Now;
            spSign.HashedSubPackets = new SignatureSubPacket[2];
            spSign.HashedSubPackets[0] = sspCreator;
            spSign.HashedSubPackets[1] = sspCreationTime;

            wWorking.Progress(20);

            //spSign.KeyID = skpKey.PublicKey.KeyID;
            //spSign.TimeCreated = DateTime.Now;
            spSign.SignatureAlgorithm = skpKey.PublicKey.Algorithm;
            spSign.SignatureType = SignatureTypes.TextSignature;
            spSign.Version = SignaturePacketVersionNumbers.v4;

            wWorking.Progress(10);

            byte[] bMessage = System.Text.Encoding.UTF8.GetBytes(strMessage);
            spSign.Sign(bMessage, skpKey, strPassphrase);

            wWorking.Progress(40);
            byte[] bSignature = spSign.Generate();

            string strSignature = Radix64.Encode(bSignature, true);

            wWorking.Progress(20);

            string strFinal = Armor.WrapCleartextSignature(strMessage, strSignature);

            wWorking.Hide();

            return strFinal;
        }