DelphiCSPRNG
1.0.0
Delphi 的跨平台加密安全伪随机数生成器
我想要一个易于使用的跨平台随机数生成器,它比内置的随机数生成器更可靠。它是模块化的,因此您可以只包含您想要的部件。利用每个平台的平台安全随机提供程序,并具有通用的提供程序接口。我只在 Win32、Win64、Android64 和 Linux64 上测试过。
有一些基本测试和示例应用程序。开放反馈、问题报告和拉取请求。特别是如果你想在苹果硬件上测试它。
免责声明:在将代码用于任何重要的事情之前,请确保您理解任何代码。仅仅因为我称之为“加密安全”并不一定意味着它是安全的或适合密码学。
uses CSPRNG, CSPRNG.Interfaces;
// /
var rng: ICSPRNGProvider := GetCSPRNGProvider;
Writeln(rng.GetFloat);
Writeln(rng.GetUInt64);
Writeln(rng.GetBase64);
type
ICSPRNGProvider = interface
// Generates a specified number of cryptographically secure random bytes.
function GetBytes ( const Count: Integer): TBytes;
// Generates a cryptographically secure random unsigned 32-bit integer.
function GetUInt32 ( const max: UInt32 = High(UInt32)): UInt32;
// Generates a cryptographically secure random signed 32-bit integer.
function GetInt32 ( const max: Int32 = High(Int32)): Int32;
// Generates a cryptographically secure random signed 64-bit integer.
function GetInt64 ( const max: Int64 = High(Int64)): Int64;
// Generates a cryptographically secure random unsigned 64-bit integer.
function GetUInt64 ( const max: UInt64 = High(UInt64)): UInt64;
// Generates a cryptographically secure random float between 0 and 1
function GetFloat : Double;
// Generates a BASE64 encoded random string
function GetBase64 ( const len: Integer = 1024 ): String;
end ;
大多数功能来自基本实现,平台特定实现提供GetBytes
函数。