예제 #1
0
        private byte[] SerpentB(byte[] Key, byte[] Data)
        {
            int len = Data.Length;
            int ct  = 0;

            byte[]        output  = new byte[len];
            SerpentEngine serpent = new SerpentEngine();

            serpent.Init(true, Key);

            while (ct < len)
            {
                serpent.ProcessBlock(Data, ct, output, ct);
                ct += 16;
            }

            return(output);
        }
예제 #2
0
        /// <summary>
        /// Encrypted the data.
        /// </summary>
        /// <param name="data">The data to encrypted.</param>
        /// <param name="passphrase">The passphrase key used to mask the data.</param>
        /// <returns>The encrypted data.</returns>
        public byte[] Encrypt(byte[] data, string passphrase)
        {
            // Create the key parameters.
            byte[] key = Encoding.Default.GetBytes(passphrase);
            Key.Crypto.Parameters.KeyParameter keyParameter = new KeyParameter(key);

            // Initialise the cryptography engine.
            Key.Crypto.Engines.SerpentEngine serpent = new SerpentEngine();
            serpent.Init(true, keyParameter);

            int dataLength   = data.Length;
            int blockSize    = serpent.GetBlockSize();
            int modBlockSize = dataLength % blockSize;
            int blockCount   = dataLength / blockSize;

            // If there is a remained then add en extra block count.
            if ((modBlockSize) > 0)
            {
                // Add one extra block.
                blockCount++;
            }

            // Encrypted data store.
            byte[] encryptedData = new byte[blockCount * blockSize];
            byte[] decryptedData = new byte[blockCount * blockSize];

            // Copy the decrypted data.
            for (int j = 0; j < dataLength; j++)
            {
                // Assign the data.
                decryptedData[j] = data[j];
            }

            // For each block size in the the data.
            for (int i = 0; i < blockCount; i++)
            {
                // Encrypt the block.
                serpent.ProcessBlock(decryptedData, (i * blockSize), encryptedData, (i * blockSize));
            }

            // Return the encrypted data.
            return(encryptedData);
        }
예제 #3
0
        private byte[] SerpentB(byte[] Key, byte[] Data)
        {
            int len = Data.Length;
            int ct = 0;
            byte[] output = new byte[len];
            SerpentEngine serpent = new SerpentEngine();

            serpent.Init(true, Key);

            while (ct < len)
            {
                serpent.ProcessBlock(Data, ct, output, ct);
                ct += 16;
            }

            return output;
        }