Пример #1
0
 /// <summary>
 /// Decrypts a single block, running the 64 bits of data through all 16
 /// rounds of the Blowfish algorithm. Returns the decrypted 64 bits.
 /// </summary>
 /// <param name="block64"></param>
 /// <param name="Schedule"></param>
 /// <returns></returns>
 public UInt64 DecryptSingleBlock(UInt64 block64)
 {
     if (Context == null)
     {
         Context = new BlowfishContext(Key);
     }
     return(BlowfishEngine.Decrypt(block64, Context));
 }
Пример #2
0
        /// <summary>
        /// Decrypts a single block, running the 64 bits of data through all 16
        /// rounds of the Blowfish algorithm. Returns the decrypted 64 bits.
        /// </summary>
        /// <param name="block64"></param>
        /// <param name="Schedule"></param>
        /// <returns></returns>
        public byte[] DecryptSingleBlock(byte[] block64, int Offset = 0)
        {
            UInt64 Block = ByteOperations.PackBytesIntoUInt64(block64, Offset);

            if (Context == null)
            {
                Context = new BlowfishContext(Key);
            }

            return(ByteOperations.UnpackUInt64IntoBytes(BlowfishEngine.Decrypt(Block, Context)));
        }
Пример #3
0
        /// <summary>
        /// Transforms the specified region of the specified byte array.
        /// </summary>
        /// <param name="inputBuffer">The input for which to compute the transform.</param>
        /// <param name="inputOffset">The offset into the byte array from which to begin using data.</param>
        /// <param name="inputCount">The number of bytes in the byte array to use as data.</param>
        /// <returns>The computed transform.</returns>
        public byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount)
        {
            UInt64 block = ByteOperations.PackBytesIntoUInt64(inputBuffer, inputOffset);

            // Call a function from the blowfish engine function.
            if (Mode == BlowfishManagedTransformMode.Encrypt)
            {
                block = BlowfishEngine.Encrypt(block, Context);
            }
            if (Mode == BlowfishManagedTransformMode.Decrypt)
            {
                block = BlowfishEngine.Decrypt(block, Context);
            }

            return(ByteOperations.UnpackUInt64IntoBytes(block));
        }
Пример #4
0
        /// <summary>
        /// Transforms the specified region of the input byte array and copies the resulting transform to the specified
        /// region of the output byte array.
        /// </summary>
        /// <param name="inputBuffer">The input for which to compute the transform.</param>
        /// <param name="inputOffset">The offset into the input byte array from which to begin using data.</param>
        /// <param name="inputCount">The number of bytes in the input byte array to use as data.</param>
        /// <param name="outputBuffer">The output to which to write the transform.</param>
        /// <param name="outputOffset">The offset into the output byte array from which to begin writing data.</param>
        /// <returns>The number of bytes written.</returns>
        public int TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)
        {
            UInt64 block = ByteOperations.PackBytesIntoUInt64(inputBuffer, inputOffset);

            // Call a function from the blowfish engine function.
            if (Mode == BlowfishManagedTransformMode.Encrypt)
            {
                block = BlowfishEngine.Encrypt(block, Context);
            }
            if (Mode == BlowfishManagedTransformMode.Decrypt)
            {
                block = BlowfishEngine.Decrypt(block, Context);
            }

            byte[] TransformedBytes = ByteOperations.UnpackUInt64IntoBytes(block);

            Array.Copy(TransformedBytes, 0, outputBuffer, outputOffset, TransformedBytes.Length);
            return(TransformedBytes.Length);
        }