本文整理汇总了C#中RandomGenerator.NextBytes方法的典型用法代码示例。如果您正苦于以下问题:C# RandomGenerator.NextBytes方法的具体用法?C# RandomGenerator.NextBytes怎么用?C# RandomGenerator.NextBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RandomGenerator
的用法示例。
在下文中一共展示了RandomGenerator.NextBytes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PackModules
void PackModules(ConfuserContext context, CompressorContext compCtx, ModuleDef stubModule, ICompressionService comp, RandomGenerator random)
{
int maxLen = 0;
var modules = new Dictionary<string, byte[]>();
for (int i = 0; i < context.OutputModules.Count; i++) {
if (i == compCtx.ModuleIndex)
continue;
string name = context.Modules[i].Assembly.Name.ToUpperInvariant();
modules.Add(name, context.OutputModules[i]);
int strLen = Encoding.UTF8.GetByteCount(name);
if (strLen > maxLen)
maxLen = strLen;
}
foreach (var extModule in context.ExternalModules) {
var name = GetName(extModule).ToUpperInvariant();
modules.Add(name, extModule);
int strLen = Encoding.UTF8.GetByteCount(name);
if (strLen > maxLen)
maxLen = strLen;
}
byte[] key = random.NextBytes(4 + maxLen);
key[0] = (byte)(compCtx.EntryPointToken >> 0);
key[1] = (byte)(compCtx.EntryPointToken >> 8);
key[2] = (byte)(compCtx.EntryPointToken >> 16);
key[3] = (byte)(compCtx.EntryPointToken >> 24);
for (int i = 4; i < key.Length; i++) // no zero bytes
key[i] |= 1;
compCtx.KeySig = key;
int moduleIndex = 0;
foreach (var entry in modules) {
byte[] name = Encoding.UTF8.GetBytes(entry.Key);
for (int i = 0; i < name.Length; i++)
name[i] *= key[i + 4];
uint state = 0x6fff61;
foreach (byte chr in name)
state = state * 0x5e3f1f + chr;
byte[] encrypted = compCtx.Encrypt(comp, entry.Value, state, progress => {
progress = (progress + moduleIndex) / modules.Count;
context.Logger.Progress((int)(progress * 10000), 10000);
});
context.CheckCancellation();
var resource = new EmbeddedResource(Convert.ToBase64String(name), encrypted, ManifestResourceAttributes.Private);
stubModule.Resources.Add(resource);
moduleIndex++;
}
context.Logger.EndProgress();
}