資源簡(jiǎn)介
blowfish加密解密算法的C#實(shí)現(xiàn),blowfish加密解密算法的C#實(shí)現(xiàn)

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Text;
namespace?BlowfishClass
{
????public?class?Blowfish
????{
????????private?BlowfishCBC?m_bfish;
????????public?Blowfish(String?key)
????????{
????????????ASCIIEncoding?encoding?=?new?ASCIIEncoding();
????????????m_bfish?=?new?BlowfishCBC(encoding.GetBytes(key)?0L);
????????}
????????~Blowfish()
????????{
????????????m_bfish.CleanUp();
????????}
????????public?String?EncryptString(String?sPlainText)
????????{
????????????long?lCBCIV;
????????????Random?rm?=?new?Random();
????????????int?hi?=?rm.Next();
????????????int?lo?=?rm.Next();
????????????lCBCIV?=?PublicFuntion.MakeLong(lo?hi);
????????????return?EncStr(sPlainText?lCBCIV);
????????}
????????private?String?EncStr(String?sPlainText?long?lNewCBCIV)
????????{
????????????int?nStrLen?=?sPlainText.Length;
????????????byte[]?buf?=?new?byte[(nStrLen?<1?&?-8)?+?8];
????????????int?nPos?=?0;
????????????for?(int?nI?=?0;?nI?????????????{
????????????????char?cActChar?=?sPlainText[nI];
????????????????buf[nPos++]?=?(byte)(cActChar?>>?8?&?0xff);
????????????????buf[nPos++]?=?(byte)(cActChar?&?0xff);
????????????}
????????????byte?bPadVal?=?(byte)(buf.Length?-?(nStrLen?<1));
????????????while?(nPos?????????????{
????????????????buf[nPos++]?=?bPadVal;
????????????}
????????????m_bfish.SetCBCIV(lNewCBCIV);
????????????m_bfish.Encrypt(buf);
????????????byte[]?newCBCIV?=?new?byte[8];
????????????PublicFuntion.LongToByteArray(lNewCBCIV?newCBCIV?0);
????????????return?PublicFuntion.BytesToBinHex(newCBCIV?0?8)?+?PublicFuntion.BytesToBinHex(buf?0?buf.Length);
????????}
????????public?String?DecryptString(String?sCipherText)
????????{
????????????int?nLen?=?sCipherText.Length?>>?1?&?-8;
????????????if?(nLen?8)
????????????{
????????????????return?null;
????????????}
????????????byte[]?cbciv?=?new?byte[8];
????????????int?nNumOfBytes?=?PublicFuntion.BinHexToBytes(sCipherText?cbciv?0?0?8);
????????????if?(nNumOfBytes?8)
????????????{
????????????????return?null;
????????????}
????????????m_bfish.SetCBCIV(cbciv);
????????????if?((nLen?-=?8)?==?0)
????????????{
????????????????return?““;
????????????}
????????????byte[]?buf?=?new?byte[nLen];
????????????nNumOfBytes?=?PublicFuntion.BinHexToBytes(sCipherText?buf?16?0?nLen);
????????????if?(nNumOfBytes?????????????{
????????????????return?null;
????????????}
????????????m_bfish.Decrypt(buf);
????????????int?nPadByte?=?buf[buf.Length?-?1]?&?0xff;
????????????if?(nPadByte?>?8?||?nPadByte?0)
????????????{
????????????????nPadByte?=?0;
????????????}
????????????nNumOfBytes?-=?nPadByte;
????????????if?(nNumOfBytes?0)
????????????{
????????????????return?““;
????????????}
????????????else
????????????{
????????????????return?PublicFuntion.ByteArrayToUNCString(buf?0?nNumOfBytes);
????????????}
????????}
????}
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件??????28672??2009-10-14?16:29??BlowfishClass\BlowfishClass\bin\Debug\BlowfishClass.dll
?????文件??????38400??2009-10-14?16:29??BlowfishClass\BlowfishClass\bin\Debug\BlowfishClass.pdb
?????文件???????2969??2009-10-14?16:29??BlowfishClass\BlowfishClass\Blowfish.cs
?????文件???????1669??2009-10-14?16:23??BlowfishClass\BlowfishClass\BlowfishCBC.cs
?????文件???????2093??2009-10-14?16:24??BlowfishClass\BlowfishClass\BlowfishClass.csproj
?????文件??????26712??2009-10-14?16:22??BlowfishClass\BlowfishClass\BlowfishECB.cs
?????文件????????158??2009-10-14?16:30??BlowfishClass\BlowfishClass\obj\BlowfishClass.csproj.FileList.txt
?????文件??????28672??2009-10-14?16:29??BlowfishClass\BlowfishClass\obj\Debug\BlowfishClass.dll
?????文件??????38400??2009-10-14?16:29??BlowfishClass\BlowfishClass\obj\Debug\BlowfishClass.pdb
?????文件???????1345??2009-10-14?16:18??BlowfishClass\BlowfishClass\Properties\AssemblyInfo.cs
?????文件???????4994??2009-10-14?16:20??BlowfishClass\BlowfishClass\PublicFuntion.cs
?????文件???????1433??2009-10-14?16:27??BlowfishClass\BlowfishClass.sln
????..A..H.?????16384??2009-10-14?16:31??BlowfishClass\BlowfishClass.suo
?????文件??????28672??2009-10-14?16:29??BlowfishClass\BlowfishClassTest\bin\Debug\BlowfishClass.dll
?????文件??????38400??2009-10-14?16:29??BlowfishClass\BlowfishClassTest\bin\Debug\BlowfishClass.pdb
?????文件??????16384??2009-10-14?16:29??BlowfishClass\BlowfishClassTest\bin\Debug\BlowfishClassTest.exe
?????文件??????11776??2009-10-14?16:29??BlowfishClass\BlowfishClassTest\bin\Debug\BlowfishClassTest.pdb
?????文件???????5632??2005-12-08?14:51??BlowfishClass\BlowfishClassTest\bin\Debug\BlowfishClassTest.vshost.exe
?????文件???????2195??2009-10-14?16:27??BlowfishClass\BlowfishClassTest\BlowfishClassTest.csproj
?????文件????????232??2009-10-14?16:30??BlowfishClass\BlowfishClassTest\obj\BlowfishClassTest.csproj.FileList.txt
?????文件??????16384??2009-10-14?16:29??BlowfishClass\BlowfishClassTest\obj\Debug\BlowfishClassTest.exe
?????文件??????11776??2009-10-14?16:29??BlowfishClass\BlowfishClassTest\obj\Debug\BlowfishClassTest.pdb
?????文件???????2564??2009-10-14?16:29??BlowfishClass\BlowfishClassTest\obj\Debug\ResolveAssemblyReference.cache
?????文件????????935??2009-10-14?16:29??BlowfishClass\BlowfishClassTest\Program.cs
?????文件???????1205??2009-10-14?16:26??BlowfishClass\BlowfishClassTest\Properties\AssemblyInfo.cs
?????目錄??????????0??2009-10-14?16:31??BlowfishClass\BlowfishClass\obj\Debug\Refactor
?????目錄??????????0??2009-10-14?16:31??BlowfishClass\BlowfishClass\obj\Debug\TempPE
?????目錄??????????0??2009-10-14?16:31??BlowfishClass\BlowfishClassTest\obj\Debug\Refactor
?????目錄??????????0??2009-10-14?16:31??BlowfishClass\BlowfishClassTest\obj\Debug\TempPE
?????目錄??????????0??2009-10-14?16:31??BlowfishClass\BlowfishClass\bin\Debug
............此處省略15個(gè)文件信息
評(píng)論
共有 條評(píng)論