国密算法SM3验证与SM4文件加密工具CBC模式


实现国密SM3算法验证和SM4算法CBC模式下文件加密操作,基于.net环境VS2017开发。
资源截图
代码片段和文件信息
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
  

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件    2277376  2019-01-15 16:05  smHelperinDebugBouncyCastle.dll

     文件    1453726  2019-01-15 16:05  smHelperinDebugBouncyCastle.xml

     文件      13312  2019-01-16 17:58  smHelperinDebugSmHelper.dll

     文件      38400  2019-01-16 17:58  smHelperinDebugSmHelper.pdb

     文件      10648  2019-01-16 17:41  smHelpercipherSM3Digest.cs

     文件      14323  2019-01-16 17:30  smHelpercipherSM4.cs

     文件       3565  2019-01-16 16:23  smHelpercipherSM4Utils.cs

     文件        620  2019-01-16 16:18  smHelpercipherSM4_Context.cs

     文件       5831  2019-01-16 17:31  smHelperobjDebugDesignTimeResolveAssemblyReferencesInput.cache

     文件          0  2019-01-16 17:58  smHelperobjDebugsmHelper.csproj.CopyComplete

     文件         42  2019-01-16 17:31  smHelperobjDebugsmHelper.csproj.CoreCompileInputs.cache

     文件        580  2019-01-16 17:29  smHelperobjDebugsmHelper.csproj.FileListAbsolute.txt

     文件       4451  2019-01-16 17:29  smHelperobjDebugsmHelper.csprojResolveAssemblyReference.cache

     文件      13312  2019-01-16 17:58  smHelperobjDebugSmHelper.dll

     文件      38400  2019-01-16 17:58  smHelperobjDebugSmHelper.pdb

     文件       1305  2019-01-10 16:59  smHelperPropertiesAssemblyInfo.cs

     文件       2199  2019-01-16 17:58  smHelpersmHelper.csproj

     文件    2277376  2019-01-15 16:05  smToolsinDebugBouncyCastle.dll

     文件    1453726  2019-01-15 16:05  smToolsinDebugBouncyCastle.xml

     文件      13312  2019-01-16 17:58  smToolsinDebugSmHelper.dll

     文件      38400  2019-01-16 17:58  smToolsinDebugSmHelper.pdb

     文件      12800  2019-01-16 18:13  smToolsinDebugSmTools.exe

     文件      24064  2019-01-16 18:13  smToolsinDebugSmTools.pdb

     文件       8772  2019-01-16 18:13  smToolsForm1.cs

     文件       7898  2019-01-16 17:24  smToolsForm1.Designer.cs

     文件       5817  2019-01-16 17:24  smToolsForm1.resx

     文件       1230  2019-01-10 17:56  smToolsobjDebugDesignTimeResolveAssemblyReferences.cache

     文件       6189  2019-01-16 18:12  smToolsobjDebugDesignTimeResolveAssemblyReferencesInput.cache

     文件        180  2019-01-16 18:13  smToolsobjDebugHmH.Form.SmTools.Properties.Resources.resources

     文件          0  2019-01-16 18:13  smToolsobjDebugsmTools.csproj.CopyComplete

............此处省略36个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)