コード例 #1
0
        /// <summary>
        /// Generates an ecrypted password file at the specified path.
        /// If the path contains directories that do not exist, they will be created automatically.
        /// </summary>
        /// <param name="text">The text to be encrypted.</param>
        /// <param name="path">A relative path specifying where in the password store the password file should be generated.</param>
        public void EncryptText(string text, string path)
        {
            var fullPath = GetPasswordFilePath(path);

            Directory.CreateDirectory(Path.GetDirectoryName(fullPath));
            Gpg.Encrypt(text, fullPath, GetGpgIds(fullPath));
        }
コード例 #2
0
        public void TestEncryptDecrypt()
        {
            Gpg g = new Gpg(GPG_BINARY_PATH);

            g.LocalUser  = GPG_LOCAL_USER_KEY;
            g.Recipient  = GPG_RECIPIENT_KEY;
            g.Passphrase = GPG_PASSWORD;

            byte[]       data       = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04 };
            MemoryStream cleartext  = new MemoryStream(data);
            MemoryStream ciphertext = new MemoryStream();

            g.Encrypt(cleartext, ciphertext);

            ciphertext.Position = 0;
            MemoryStream cleartext2 = new MemoryStream();

            g.Decrypt(ciphertext, cleartext2);

            assertEqual(cleartext, cleartext2);
        }