文档详情

Blowfish算法C#实现.doc

发布:2018-02-27约1.79万字共11页下载文档
文本预览下载声明
Blowfish算法C#实现 using System; namespace Blowfish_NET { /// summary /// Blowfish CBC implementation. /// /summary /// remarks /// Use this class to encrypt or decrypt byte arrays or a single blocks /// with Blowfish in CBC (Cipher Block Block Chaining) mode. This is the /// recommended way to use Blowfish.NET, unless certain requirements /// (e.g. moving block without decryption) exist. /// /remarks public class BlowfishCBC : BlowfishECB { // (we store the IV as two 32bit integers, to void packing and // unpacking inbetween the handling of data chunks) uint m_ivHi; uint m_ivLo; ////////////////////////////////////////////////////////////////////// /// summary /// The current initialization vector (IV), which measures one /// block. Property for convient read and writes. /// /summary public byte[] IV { set { SetIV(value, 0); } get { byte[] result = new byte[BLOCK_SIZE]; GetIV(result, 0); return result; } } ////////////////////////////////////////////////////////////////////// /// summary /// Sets the initialization vector (IV). /// /summary /// param name=bufbuffer containing the new IV material/param /// param name=nOfswhere the IV material starts/param public void SetIV( byte[] buf, int nOfs) { m_ivHi = (((uint)buf[nOfs ]) 24) | (((uint)buf[nOfs + 1]) 16) | (((uint)buf[nOfs + 2]) 8) | buf[nOfs + 3]; m_ivLo = (((uint)buf[nOfs + 4]) 24) | (((uint)buf[nOfs + 5]) 16) | (((uint)buf[nOfs + 6]) 8) | buf[nOfs + 7];
显示全部
相似文档