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"); } }
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); }); }
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); }
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(); } }
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)); }
public void SignZeroBytes() { byte[] signature = PGPUtilities.Sign(new byte[0], privKey, PrivKeyPassword); Assert.NotNull(Encoding.ASCII.GetString(signature)); }
public void SignNullPassword() { Assert.Throws(typeof(NullReferenceException), () => { PGPUtilities.Sign(new byte[0], privKey, null); }); }
public void SignNullKey() { Assert.Throws(typeof(PgpKeyValidationException), () => { PGPUtilities.Sign(new byte[0], null, PrivKeyPassword); }); }
public void SignNullBytes() { Assert.Throws(typeof(NullReferenceException), () => { PGPUtilities.Sign(null, privKey, PrivKeyPassword); }); }
public void SignBlankKey() { Assert.Throws(typeof(PgpKeyValidationException), () => { PGPUtilities.Sign(new byte[0], string.Empty, PrivKeyPassword); }); }
public void SignBadPassword() { Assert.Throws(typeof(PgpException), () => { PGPUtilities.Sign(new byte[0], privKey, string.Empty); }); }
/// <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)); }
public void VerifyNulls() { string str = null; Assert.Throws(typeof(PgpDataValidationException), () => { PGPUtilities.Verify(str, null); }); }
public void VerifyBadSignature() { Assert.Throws(typeof(PgpDataValidationException), () => { PGPUtilities.Verify(new byte[0], publKey); }); }