Esempio n. 1
0
        // Not working yet
        //[Test]
        public void ClearTextSignTest()
        {
            var context = new CryptoContext(
                GetPasswordCallback,
                @"C:\projects\OutlookPrivacyPlugin\Deja.Crypto.Test\pubring.gpg",
                @"C:\projects\OutlookPrivacyPlugin\Deja.Crypto.Test\secring.gpg",
                "rsa", "sha-1");
            var crypto = new PgpCrypto(context);

            var dataDir = @"C:\projects\OutlookPrivacyPlugin\Deja.Crypto.Test\data";
            var signKey = "*****@*****.**";
            var sign    = string.Empty;

            foreach (var file in Directory.EnumerateFiles(dataDir, "*.bin"))
            {
                Console.WriteLine("ClearTextSignTest: " + file);

                context.Digest = "sha-1";
                sign           = crypto.SignClear(File.ReadAllText(file), signKey, Encoding.UTF8, new Dictionary <string, string>());
                File.WriteAllText(@"c:\temp\test.bin", sign);
                Assert.AreEqual(File.ReadAllText(file + ".rsa.sha1.clearsign"), sign);

                context.Digest = "SHA-256";
                sign           = crypto.SignClear(File.ReadAllText(file), signKey, Encoding.UTF8, new Dictionary <string, string>());
                Assert.AreEqual(File.ReadAllText(file + ".rsa.sha256.clearsign"), sign);

                context.Digest = "SHA-1";
                sign           = crypto.Sign(File.ReadAllBytes(file), signKey, new Dictionary <string, string>());
                File.WriteAllText(@"c:\temp\test.bin", sign);
                Assert.AreEqual(File.ReadAllText(file + ".rsa.sha1.sign"), sign);
            }
        }
Esempio n. 2
0
        public void UnicodeUtf8PageTest()
        {
            var clear = @"Hi Meddington,

i think i have found the issue.
I write this mail as - only text - message.
If another receive this email, my signature email and webaddress are i
nterpreted as links and will be changed by outlook to html elements.


Mit freundlichen Grüßen,
Sebastian Lutz

Baebeca Solutions - Lutz
E-Mail: [email protected]
Tel. Büro: 02261 - 9202935
Tel. Mobil: 0171 - 6431821
Web: https://www.baebeca.de
PGP Key: 0x5AD0240C
";

            var context = new CryptoContext(GetPasswordCallback, Pubring, Secring, "rsa", "sha-1");
            var crypto  = new PgpCrypto(context);

            var clearSig = crypto.SignClear(clear, "*****@*****.**", Encoding.UTF8, new Dictionary <string, string>());
            var ret      = crypto.VerifyClear(Encoding.UTF8.GetBytes(clearSig));

            Assert.IsTrue(ret);
        }
	    private string SignEmail(string data, string key)
		{
			try
			{
				if (!PromptForPasswordAndKey())
					return null;

				var context = new CryptoContext(Passphrase);
				var crypto = new PgpCrypto(context);
				var headers = new Dictionary<string, string>();
				headers["Version"] = MailHeaderVersion;

				return crypto.SignClear(data, key, _encoding, headers);
			}
			catch (CryptoException ex)
			{
				Passphrase = null;

				WriteErrorData("SignEmail", ex);
				ShowErrorBox(ex.Message);

				return null;
			}
		}