资源简介
国家商用密码算法开放动态库及演示程序,支持如下国家商业密码算法:SM2、SM3、SM4。国密算法SM2、SM3、SM4的C#源码
代码片段和文件信息
using System;
using System.Globalization;
using System.Text;
namespace smcrypto
{
///
/// 字节数组操作扩展类
///
static class ByteUtils
{
internal static byte[] AsciiBytes(string s)
{
byte[] bytes = new byte[s.Length];
for (int i = 0; i < s.Length; i++)
{
bytes[i] = (byte)s[i];
}
return bytes;
}
internal static byte[] HexToByteArray(this string hexString)
{
byte[] bytes = new byte[hexString.Length / 2];
for (int i = 0; i < hexString.Length; i += 2)
{
string s = hexString.Substring(i 2);
bytes[i / 2] = byte.Parse(s Numberstyles.HexNumber null);
}
return bytes;
}
internal static string ByteArrayToHex(this byte[] bytes)
{
StringBuilder builder = new StringBuilder(bytes.Length * 2);
foreach (byte b in bytes)
{
builder.Append(b.ToString(“X2“));
}
return builder.ToString();
}
internal static string ByteArrayToHex(this byte[] bytes int len)
{
return ByteArrayToHex(bytes).Substring(0 len * 2);
}
internal static byte[] RepeatByte(byte b int count)
{
byte[] value = new byte[count];
for (int i = 0; i < count; i++)
{
value[i] = b;
}
return value;
}
internal static byte[] SubBytes(this byte[] bytes int startIndex int length )
{
byte[] res = new byte[length];
Array.Copy(bytes startIndex res 0 length);
return res;
}
internal static byte[] XOR(this byte[] value)
{
byte[] res = new byte[value.Length];
for (int i = 0; i < value.Length; i++)
{
res[i] ^= value[i];
}
return res;
}
internal static byte[] XOR(this byte[] valueA byte[] valueB)
{
int len = valueA.Length;
byte[] res = new byte[len];
for (int i = 0; i < len; i++)
{
res[i] = (byte)(valueA[i] ^ valueB[i]);
}
return res;
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-08-21 15:07 smcrypto-master\
文件 2518 2017-08-21 15:07 smcrypto-master\.gitattributes
文件 4305 2017-08-21 15:07 smcrypto-master\.gitignore
文件 1095 2017-08-21 15:07 smcrypto-master\smcrypto.sln
目录 0 2017-08-21 15:07 smcrypto-master\smcrypto\
文件 2401 2017-08-21 15:07 smcrypto-master\smcrypto\ByteUtils.cs
文件 3916 2017-08-21 15:07 smcrypto-master\smcrypto\Chiper.cs
文件 554 2017-08-21 15:07 smcrypto-master\smcrypto\Program.cs
目录 0 2017-08-21 15:07 smcrypto-master\smcrypto\Properties\
目录 0 2017-08-21 15:07 smcrypto-master\smcrypto\Properties\PublishProfiles\
文件 610 2017-08-21 15:07 smcrypto-master\smcrypto\Properties\PublishProfiles\FolderProfile.pubxm
文件 4155 2017-08-21 15:07 smcrypto-master\smcrypto\SM2.cs
文件 4254 2017-08-21 15:07 smcrypto-master\smcrypto\SM2Utils.cs
文件 11151 2017-08-21 15:07 smcrypto-master\smcrypto\SM3.cs
文件 11317 2017-08-21 15:07 smcrypto-master\smcrypto\SM4.cs
文件 3777 2017-08-21 15:07 smcrypto-master\smcrypto\SM4Utils.cs
文件 274 2017-08-21 15:07 smcrypto-master\smcrypto\smcrypto.csproj
- 上一篇:C# 模拟电梯控制源码
- 下一篇:wince条码扫描支持一维二维
评论
共有 条评论