Пример #1
0
 public void GenerateKey()
 {
     using (var publicKeyStream = new MemoryStream())
         using (var privateKeyStream = new MemoryStream()) {
             //PGPUtilities.GenerateKey(@"C:\TEMP\keys\public.asc", @"C:\TEMP\keys\private.asc", "*****@*****.**", "password");
             PGPUtilities.GenerateKey(publicKeyStream, privateKeyStream, "*****@*****.**", "password");
         }
 }
Пример #2
0
        public void VerifyWrongKey()
        {
            string text = "hello world!";

            byte[] signature = GetSignature(text);

            Assert.NotNull(signature);
            Assert.AreNotEqual(0, signature.Length);

            Assert.Throws(typeof(PgpDataValidationException), () => { PGPUtilities.Verify(signature, newPublicKey); });
        }
Пример #3
0
        public void Sign()
        {
            string text = "hello world!";

            byte[] bytes          = Encoding.ASCII.GetBytes(text);
            byte[] signatureBytes = PGPUtilities.Sign(bytes, privKey, PrivKeyPassword);

            string signature = Encoding.ASCII.GetString(signatureBytes);

            Assert.NotNull(signature);
            Assert.AreNotEqual(string.Empty, signature);
        }
Пример #4
0
        public void GenerateKey(string username = null, string password = null)
        {
            using (var publicKeyStream = new MemoryStream())
                using (var privateKeyStream = new MemoryStream()) {
                    PGPUtilities.GenerateKey(publicKeyStream, privateKeyStream, username, password);

                    publicKeyStream.Seek(0, SeekOrigin.Begin);
                    privateKeyStream.Seek(0, SeekOrigin.Begin);

                    PublicKey  = publicKeyStream.Stringify();
                    PrivateKey = privateKeyStream.Stringify();
                }
        }
Пример #5
0
        public void VerifyString()
        {
            string text      = "hello again world!";
            string signature = GetSignatureString(text);

            Assert.NotNull(signature);
            Assert.AreNotEqual(string.Empty, signature);

            byte[] message = PGPUtilities.Verify(signature, publKey);

            Assert.NotNull(message);
            Assert.AreNotEqual(0, message.Length);
            Assert.AreEqual(text, Encoding.ASCII.GetString(message));
        }
Пример #6
0
        public void SignZeroBytes()
        {
            byte[] signature = PGPUtilities.Sign(new byte[0], privKey, PrivKeyPassword);

            Assert.NotNull(Encoding.ASCII.GetString(signature));
        }
Пример #7
0
 public void SignNullPassword()
 {
     Assert.Throws(typeof(NullReferenceException), () => { PGPUtilities.Sign(new byte[0], privKey, null); });
 }
Пример #8
0
 public void SignNullKey()
 {
     Assert.Throws(typeof(PgpKeyValidationException), () => { PGPUtilities.Sign(new byte[0], null, PrivKeyPassword); });
 }
Пример #9
0
 public void SignNullBytes()
 {
     Assert.Throws(typeof(NullReferenceException), () => { PGPUtilities.Sign(null, privKey, PrivKeyPassword); });
 }
Пример #10
0
 public void SignBlankKey()
 {
     Assert.Throws(typeof(PgpKeyValidationException), () => { PGPUtilities.Sign(new byte[0], string.Empty, PrivKeyPassword); });
 }
Пример #11
0
 public void SignBadPassword()
 {
     Assert.Throws(typeof(PgpException), () => { PGPUtilities.Sign(new byte[0], privKey, string.Empty); });
 }
Пример #12
0
 /// <summary>
 ///     Returns a PGP signature of the specified text using the default private key.
 /// </summary>
 /// <param name="text">The text for which the signature will be generated.</param>
 /// <returns>The generated PGP signature.</returns>
 private byte[] GetSignature(string text)
 {
     byte[] bytes = Encoding.ASCII.GetBytes(text);
     return(PGPUtilities.Sign(bytes, privKey, PrivKeyPassword));
 }
Пример #13
0
        public void VerifyNulls()
        {
            string str = null;

            Assert.Throws(typeof(PgpDataValidationException), () => { PGPUtilities.Verify(str, null); });
        }
Пример #14
0
 public void VerifyBadSignature()
 {
     Assert.Throws(typeof(PgpDataValidationException), () => { PGPUtilities.Verify(new byte[0], publKey); });
 }