Exemplo n.º 1
0
        public static byte[] Encrypt(byte[] inputData, byte[] publickey, bool withIntegrityCheck, bool armor)
        {
            MemoryStream keyStream  = new MemoryStream(publickey);
            PgpPublicKey passPhrase = PGP.ReadPublicKey(keyStream);

            byte[] processedData = Compress(inputData, PgpLiteralData.Console, CompressionAlgorithmTag.Uncompressed);

            MemoryStream bOut   = new MemoryStream();
            Stream       output = bOut;

            if (armor)
            {
                output = new ArmoredOutputStream(output);
            }

            PgpEncryptedDataGenerator encGen = new PgpEncryptedDataGenerator(SymmetricKeyAlgorithmTag.Cast5, withIntegrityCheck, new SecureRandom());

            encGen.AddMethod(passPhrase);

            Stream encOut = encGen.Open(output, processedData.Length);

            encOut.Write(processedData, 0, processedData.Length);
            encOut.Flush();
            encOut.Dispose(); // encOut.Close();

            if (armor)
            {
                output.Flush(); //output.Close();
                output.Dispose();
            }

            bOut.Flush();

            return(bOut.ToArray());
        }
Exemplo n.º 2
0
        public static void GenerateKeyPair(string userid, string password, out PgpPublicKeyRing pkr, out PgpSecretKeyRing skr)
        {
            PgpKeyRingGenerator krgen = PGP.generateKeyRingGenerator(userid, password);

            // Generate public key ring, dump to file.
            pkr = krgen.GeneratePublicKeyRing();

            // Generate private key, dump to file.
            skr = krgen.GenerateSecretKeyRing();
        }