本文介绍了C#到C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
请帮我,我想将C#类转换为C代码
Please help me I want to convert below C# class to C code
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Management;
using System.Security.AccessControl;
using System.Security.Cryptography;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ZenSetGroupPolicy
{
public class SNGenerator
{
public enum
SNKeyLength
{
SN16 = 16, SN20 = 20, SN24 = 24, SN28 = 28, SN32 = 32
}
public enum SNKeyNumLength
{
SN4 = 4, SN8 = 8, SN12 =
12
}
public static class RandomSNKGenerator
{
private static string
AppendSpecifiedStr(int length, string str, char[] newKey)
{
string
newKeyStr = "";
int k = 0;
for (int i = 0; i < length; i++)
{
for
(k = i; k < 4 + i; k++)
{
newKeyStr += newKey[k];
}
if (k ==
length)
{
break;
}
else
{
i = (k) - 1;
newKeyStr +=
str;
}
}
return newKeyStr;
}
///
/// Generate
//standard serial key with alphanumaric format
///
///
//the supported length of the serial
// key
/// returns formated serial
//key
public static string GetSerialKeyAlphaNumaric(SNKeyLength
keyLength, string input)
{
string newSerialNumber = "";
using (MD5 md5 = MD5.Create())
{
byte[] hash = md5.ComputeHash(Encoding.Default.GetBytes(input));
Guid newguid = new Guid(hash);
string randomStr =
newguid.ToString("N");
string tracStr = randomStr.Substring(0,
(int)keyLength);
tracStr = tracStr.ToUpper();
char[] newKey =
tracStr.ToCharArray();
switch (keyLength
)
{
case SNKeyLength.SN16:
newSerialNumber = AppendSpecifiedStr(16,
"-", newKey);
break;
case SNKeyLength.SN20:
newSerialNumber =
AppendSpecifiedStr(20, "-", newKey);
break;
case
SNKeyLength.SN24:
newSerialNumber = AppendSpecifiedStr(24, "-",
newKey);
break;
case SNKeyLength.SN28:
newSerialNumber =
AppendSpecifiedStr(28, "-", newKey);
break;
case
SNKeyLength.SN32:
newSerialNumber = AppendSpecifiedStr(32, "-",
newKey);
break;
}
}
return newSerialNumber;
}
///
/// Generate serial key with only numaric
///
/// the supported length of
//the serial key
/// returns formated serial
//key
public static string GetSerialKeyNumaric(SNKeyNumLength
keyLength)
{
Random rn = new Random();
double sd =
Math.Round(rn.NextDouble() * Math.Pow(10, (int)keyLength) + 4);
return
sd.ToString().Substring(0, (int)keyLength);
}
}
public static void GrantAccess()
{
}
}
}
输入: SNGenerator.RandomSNKGenerator.GetSerialKeyAlphaNumaric(SNGenerator.SNKeyLength.SN20,"Hello World");
Input : SNGenerator.RandomSNKGenerator.GetSerialKeyAlphaNumaric(SNGenerator.SNKeyLength.SN20, "Hello World");
输出: B18D-0AB1-E064-4175-05B7
Output : B18D-0AB1-E064-4175-05B7
推荐答案
这篇关于C#到C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!