Exemplo n.º 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");
         }
 }
Exemplo n.º 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); });
        }
Exemplo n.º 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);
        }
Exemplo n.º 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();
                }
        }
Exemplo n.º 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));
        }
Exemplo n.º 6
0
        public void SignZeroBytes()
        {
            byte[] signature = PGPUtilities.Sign(new byte[0], privKey, PrivKeyPassword);

            Assert.NotNull(Encoding.ASCII.GetString(signature));
        }
Exemplo n.º 7
0
 public void SignNullPassword()
 {
     Assert.Throws(typeof(NullReferenceException), () => { PGPUtilities.Sign(new byte[0], privKey, null); });
 }
Exemplo n.º 8
0
 public void SignNullKey()
 {
     Assert.Throws(typeof(PgpKeyValidationException), () => { PGPUtilities.Sign(new byte[0], null, PrivKeyPassword); });
 }
Exemplo n.º 9
0
 public void SignNullBytes()
 {
     Assert.Throws(typeof(NullReferenceException), () => { PGPUtilities.Sign(null, privKey, PrivKeyPassword); });
 }
Exemplo n.º 10
0
 public void SignBlankKey()
 {
     Assert.Throws(typeof(PgpKeyValidationException), () => { PGPUtilities.Sign(new byte[0], string.Empty, PrivKeyPassword); });
 }
Exemplo n.º 11
0
 public void SignBadPassword()
 {
     Assert.Throws(typeof(PgpException), () => { PGPUtilities.Sign(new byte[0], privKey, string.Empty); });
 }
Exemplo n.º 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));
 }
Exemplo n.º 13
0
        public void VerifyNulls()
        {
            string str = null;

            Assert.Throws(typeof(PgpDataValidationException), () => { PGPUtilities.Verify(str, null); });
        }
Exemplo n.º 14
0
 public void VerifyBadSignature()
 {
     Assert.Throws(typeof(PgpDataValidationException), () => { PGPUtilities.Verify(new byte[0], publKey); });
 }