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
函數。