資源簡介
實(shí)現(xiàn)國密SM3算法驗(yàn)證和SM4算法CBC模式下文件加密操作,基于.net環(huán)境VS2017開發(fā)。

代碼片段和文件信息
using?System;
using?Org.BouncyCastle.Crypto;
namespace?HmH.base.SmHelper.cipher
{
????public?abstract?class?GeneralDigest?:?IDigest
????{
????????private?const?int?BYTE_LENGTH?=?64;
????????private?byte[]?xBuf;
????????private?int?xBufOff;
????????private?long?byteCount;
????????internal?GeneralDigest()
????????{
????????????xBuf?=?new?byte[4];
????????}
????????internal?GeneralDigest(GeneralDigest?t)
????????{
????????????xBuf?=?new?byte[t.xBuf.Length];
????????????Array.Copy(t.xBuf?0?xBuf?0?t.xBuf.Length);
????????????xBufOff?=?t.xBufOff;
????????????byteCount?=?t.byteCount;
????????}
????????public?void?Update(byte?input)
????????{
????????????xBuf[xBufOff++]?=?input;
????????????if?(xBufOff?==?xBuf.Length)
????????????{
????????????????ProcessWord(xBuf?0);
????????????????xBufOff?=?0;
????????????}
????????????byteCount++;
????????}
????????public?void?BlockUpdate(
????????????byte[]?input
????????????int?inOff
????????????int?length)
????????{
????????????//
????????????//?fill?the?current?word
????????????//
????????????while?((xBufOff?!=?0)?&&?(length?>?0))
????????????{
????????????????Update(input[inOff]);
????????????????inOff++;
????????????????length--;
????????????}
????????????//
????????????//?process?whole?words.
????????????//
????????????while?(length?>?xBuf.Length)
????????????{
????????????????ProcessWord(input?inOff);
????????????????inOff?+=?xBuf.Length;
????????????????length?-=?xBuf.Length;
????????????????byteCount?+=?xBuf.Length;
????????????}
????????????//
????????????//?load?in?the?remainder.
????????????//
????????????while?(length?>?0)
????????????{
????????????????Update(input[inOff]);
????????????????inOff++;
????????????????length--;
????????????}
????????}
????????public?void?Finish()
????????{
????????????long?bitLength?=?(byteCount?<3);
????????????//
????????????//?add?the?pad?bytes.
????????????//
????????????Update(unchecked((byte)128));
????????????while?(xBufOff?!=?0)?Update(unchecked((byte)0));
????????????ProcessLength(bitLength);
????????????ProcessBlock();
????????}
????????public?virtual?void?Reset()
????????{
????????????byteCount?=?0;
????????????xBufOff?=?0;
????????????Array.Clear(xBuf?0?xBuf.Length);
????????}
????????public?int?GetByteLength()
????????{
????????????return?BYTE_LENGTH;
????????}
????????internal?abstract?void?ProcessWord(byte[]?input?int?inOff);
????????internal?abstract?void?ProcessLength(long?bitLength);
????????internal?abstract?void?ProcessBlock();
????????public?abstract?string?AlgorithmName?{?get;?}
????????public?abstract?int?GetDigestSize();
????????public?abstract?int?DoFinal(byte[]?output?int?outOff);
????}
????public?class?SupportClass
????{
????????///?
????????///?Performs?an?unsigned?bitwise?right?shift?with?the?specified?number
????????///?
????????///Number?to?operate?on
??
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件????2277376??2019-01-15?16:05??smHelper\bin\Debug\BouncyCastle.dll
?????文件????1453726??2019-01-15?16:05??smHelper\bin\Debug\BouncyCastle.xm
?????文件??????13312??2019-01-16?17:58??smHelper\bin\Debug\SmHelper.dll
?????文件??????38400??2019-01-16?17:58??smHelper\bin\Debug\SmHelper.pdb
?????文件??????10648??2019-01-16?17:41??smHelper\cipher\SM3Digest.cs
?????文件??????14323??2019-01-16?17:30??smHelper\cipher\SM4.cs
?????文件???????3565??2019-01-16?16:23??smHelper\cipher\SM4Utils.cs
?????文件????????620??2019-01-16?16:18??smHelper\cipher\SM4_Context.cs
?????文件???????5831??2019-01-16?17:31??smHelper\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件??????????0??2019-01-16?17:58??smHelper\obj\Debug\smHelper.csproj.CopyComplete
?????文件?????????42??2019-01-16?17:31??smHelper\obj\Debug\smHelper.csproj.CoreCompileInputs.cache
?????文件????????580??2019-01-16?17:29??smHelper\obj\Debug\smHelper.csproj.FileListAbsolute.txt
?????文件???????4451??2019-01-16?17:29??smHelper\obj\Debug\smHelper.csprojResolveAssemblyReference.cache
?????文件??????13312??2019-01-16?17:58??smHelper\obj\Debug\SmHelper.dll
?????文件??????38400??2019-01-16?17:58??smHelper\obj\Debug\SmHelper.pdb
?????文件???????1305??2019-01-10?16:59??smHelper\Properties\AssemblyInfo.cs
?????文件???????2199??2019-01-16?17:58??smHelper\smHelper.csproj
?????文件????2277376??2019-01-15?16:05??smTools\bin\Debug\BouncyCastle.dll
?????文件????1453726??2019-01-15?16:05??smTools\bin\Debug\BouncyCastle.xm
?????文件??????13312??2019-01-16?17:58??smTools\bin\Debug\SmHelper.dll
?????文件??????38400??2019-01-16?17:58??smTools\bin\Debug\SmHelper.pdb
?????文件??????12800??2019-01-16?18:13??smTools\bin\Debug\SmTools.exe
?????文件??????24064??2019-01-16?18:13??smTools\bin\Debug\SmTools.pdb
?????文件???????8772??2019-01-16?18:13??smTools\Form1.cs
?????文件???????7898??2019-01-16?17:24??smTools\Form1.Designer.cs
?????文件???????5817??2019-01-16?17:24??smTools\Form1.resx
?????文件???????1230??2019-01-10?17:56??smTools\obj\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????6189??2019-01-16?18:12??smTools\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????180??2019-01-16?18:13??smTools\obj\Debug\HmH.Form.SmTools.Properties.Resources.resources
?????文件??????????0??2019-01-16?18:13??smTools\obj\Debug\smTools.csproj.CopyComplete
............此處省略36個(gè)文件信息
評論
共有 條評論