예제 #1
0
        /// ****************************************************************************
        /// Encryption and Decryption Algorithms
        /// ****************************************************************************

        public byte[] Encrypt_Serpent(string plainMessage)
        {
            CipherKeyGenerator cipherKeyGenerator = new CipherKeyGenerator();

            cipherKeyGenerator.Init(new KeyGenerationParameters(new SecureRandom(), 128));
            byte[]  key          = cipherKeyGenerator.GenerateKey();
            byte [] iv           = cipherKeyGenerator.GenerateKey();
            byte[]  encrptedDAta = SerpentAlgo.SerpentEncryption(plainMessage, key);
            return(encrptedDAta.Concat(key).Concat(iv).ToArray());
        }
예제 #2
0
        public void SerpentTest()
        {
            CipherKeyGenerator cipherKeyGenerator = new CipherKeyGenerator();

            cipherKeyGenerator.Init(new KeyGenerationParameters(new SecureRandom(), 128));
            byte[] key     = cipherKeyGenerator.GenerateKey();
            string message = "Hello World!";

            // Encrypt the string to an in-memory buffer.

            byte[] encrptedDAta = SerpentAlgo.SerpentEncryption(message, key);

            // Decrypt the buffer back to a string.
            string plainText = SerpentAlgo.SerpentDecryption(encrptedDAta, key);

            // Display the decrypted string to the console.

            Console.WriteLine(plainText);
        }