System.Hash.THashSHA2

提供: RAD Studio API Documentation
移動先: 案内検索

Delphi

  THashSHA2 = record
  public type
    TSHA2Version = (SHA224, SHA256, SHA384, SHA512, SHA512_224, SHA512_256);
  private const
    CBuffer32Length = 64;
    CBuffer64Length = 128;
  private
    FBuffer: array [0..127] of Byte;
    FBitLength: UInt64;
    FIndex: Cardinal;
    FFinalized: Boolean;
    procedure Initialize(AVersion: TSHA2Version);
    procedure CheckFinalized; inline;
    procedure Compress; inline;
    procedure Compress32;
    procedure Compress64;
    procedure Finalize; inline;
    procedure Finalize32;
    procedure Finalize64;
    function GetDigest: TBytes;
    procedure Update(const AData: PByte; ALength: Cardinal); overload;
  public
    class function Create(AHashVersion: TSHA2Version = TSHA2Version.SHA256): THashSHA2; static; inline;
    procedure Reset; inline;
    procedure Update(const AData; ALength: Cardinal); overload;
    procedure Update(const AData: TBytes; ALength: Cardinal = 0); overload; inline;
    procedure Update(const Input: string); overload; inline;
    function GetBlockSize: Integer; inline;
    function GetHashSize: Integer; inline;
    function HashAsBytes: TBytes; inline;
    function HashAsString: string; inline;
    class function GetHashBytes(const AData: string; AHashVersion: TSHA2Version = TSHA2Version.SHA256): TBytes; overload; static;
    class function GetHashString(const AString: string; AHashVersion: TSHA2Version = TSHA2Version.SHA256): string; overload; static; inline;
    class function GetHashBytes(const AStream: TStream; AHashVersion: TSHA2Version = TSHA2Version.SHA256): TBytes; overload; static;
    class function GetHashString(const AStream: TStream; AHashVersion: TSHA2Version = TSHA2Version.SHA256): string; overload; static; inline;
    class function GetHashBytesFromFile(const AFileName: TFileName; AHashVersion: TSHA2Version = TSHA2Version.SHA256): TBytes; static;
    class function GetHashStringFromFile(const AFileName: TFileName; AHashVersion: TSHA2Version = TSHA2Version.SHA256): string; static; inline;
    class function GetHMAC(const AData, AKey: string; AHashVersion: TSHA2Version = TSHA2Version.SHA256): string; static; inline;
    class function GetHMACAsBytes(const AData, AKey: string; AHashVersion: TSHA2Version = TSHA2Version.SHA256): TBytes; overload;  static;
    class function GetHMACAsBytes(const AData: string; const AKey: TBytes; AHashVersion: TSHA2Version = TSHA2Version.SHA256): TBytes; overload; static;
    class function GetHMACAsBytes(const AData: TBytes; const AKey: string; AHashVersion: TSHA2Version = TSHA2Version.SHA256): TBytes; overload; static;
    class function GetHMACAsBytes(const AData, AKey: TBytes; AHashVersion: TSHA2Version = TSHA2Version.SHA256): TBytes; overload; static;
  private
  case FVersion: TSHA2Version of
    TSHA2Version.SHA224,
    TSHA2Version.SHA256: (FHash: array[0..7] of Cardinal);
    TSHA2Version.SHA384,
    TSHA2Version.SHA512,
    TSHA2Version.SHA512_224,
    TSHA2Version.SHA512_256: (FHash64: array[0..7] of UInt64);
  end;

C++

struct DECLSPEC_DRECORD THashSHA2
{
public:
    enum DECLSPEC_DENUM TSHA2Version : unsigned char { SHA224, SHA256, SHA384, SHA512, SHA512_224, SHA512_256 };
private:
    static const System::Int8 CBuffer32Length = System::Int8(0x40);
    static const System::Byte CBuffer64Length = System::Byte(0x80);
    System::StaticArray<System::Byte, 128> FBuffer;
    unsigned __int64 FBitLength;
    unsigned FIndex;
    bool FFinalized;
    void __fastcall Initialize(TSHA2Version AVersion);
    void __fastcall CheckFinalized();
    void __fastcall Compress();
    void __fastcall Compress32();
    void __fastcall Compress64();
    void __fastcall Finalize();
    void __fastcall Finalize32();
    void __fastcall Finalize64();
#ifndef _WIN64
    System::DynamicArray<System::Byte> __fastcall GetDigest();
#else /* _WIN64 */
    System::TArray__1<System::Byte> __fastcall GetDigest();
#endif /* _WIN64 */
    void __fastcall Update(const System::PByte AData, unsigned ALength)/* overload */;
public:
    static THashSHA2 __fastcall Create(TSHA2Version AHashVersion = (TSHA2Version)(0x1));
    void __fastcall Reset();
    void __fastcall Update(const void *AData, unsigned ALength)/* overload */;
#ifndef _WIN64
    void __fastcall Update(const System::DynamicArray<System::Byte> AData, unsigned ALength = (unsigned)(0x0))/* overload */;
#else /* _WIN64 */
    void __fastcall Update(const System::TArray__1<System::Byte> AData, unsigned ALength = (unsigned)(0x0))/* overload */;
#endif /* _WIN64 */
    void __fastcall Update(const System::UnicodeString Input)/* overload */;
    int __fastcall GetBlockSize();
    int __fastcall GetHashSize();
#ifndef _WIN64
    System::DynamicArray<System::Byte> __fastcall HashAsBytes();
#else /* _WIN64 */
    System::TArray__1<System::Byte> __fastcall HashAsBytes();
#endif /* _WIN64 */
    System::UnicodeString __fastcall HashAsString();
#ifndef _WIN64
    static System::DynamicArray<System::Byte> __fastcall GetHashBytes(const System::UnicodeString AData, TSHA2Version AHashVersion = (TSHA2Version)(0x1))/* overload */;
#else /* _WIN64 */
    static System::TArray__1<System::Byte> __fastcall GetHashBytes(const System::UnicodeString AData, TSHA2Version AHashVersion = (TSHA2Version)(0x1))/* overload */;
#endif /* _WIN64 */
    static System::UnicodeString __fastcall GetHashString(const System::UnicodeString AString, TSHA2Version AHashVersion = (TSHA2Version)(0x1))/* overload */;
#ifndef _WIN64
    static System::DynamicArray<System::Byte> __fastcall GetHashBytes(System::Classes::TStream* const AStream, TSHA2Version AHashVersion = (TSHA2Version)(0x1))/* overload */;
#else /* _WIN64 */
    static System::TArray__1<System::Byte> __fastcall GetHashBytes(System::Classes::TStream* const AStream, TSHA2Version AHashVersion = (TSHA2Version)(0x1))/* overload */;
#endif /* _WIN64 */
    static System::UnicodeString __fastcall GetHashString(System::Classes::TStream* const AStream, TSHA2Version AHashVersion = (TSHA2Version)(0x1))/* overload */;
#ifndef _WIN64
    static System::DynamicArray<System::Byte> __fastcall GetHashBytesFromFile(const System::Sysutils::TFileName AFileName, TSHA2Version AHashVersion = (TSHA2Version)(0x1));
#else /* _WIN64 */
    static System::TArray__1<System::Byte> __fastcall GetHashBytesFromFile(const System::Sysutils::TFileName AFileName, TSHA2Version AHashVersion = (TSHA2Version)(0x1));
#endif /* _WIN64 */
    static System::UnicodeString __fastcall GetHashStringFromFile(const System::Sysutils::TFileName AFileName, TSHA2Version AHashVersion = (TSHA2Version)(0x1));
    static System::UnicodeString __fastcall GetHMAC(const System::UnicodeString AData, const System::UnicodeString AKey, TSHA2Version AHashVersion = (TSHA2Version)(0x1));
#ifndef _WIN64
    static System::DynamicArray<System::Byte> __fastcall GetHMACAsBytes(const System::UnicodeString AData, const System::UnicodeString AKey, TSHA2Version AHashVersion = (TSHA2Version)(0x1))/* overload */;
    static System::DynamicArray<System::Byte> __fastcall GetHMACAsBytes(const System::UnicodeString AData, const System::DynamicArray<System::Byte> AKey, TSHA2Version AHashVersion = (TSHA2Version)(0x1))/* overload */;
    static System::DynamicArray<System::Byte> __fastcall GetHMACAsBytes(const System::DynamicArray<System::Byte> AData, const System::UnicodeString AKey, TSHA2Version AHashVersion = (TSHA2Version)(0x1))/* overload */;
    static System::DynamicArray<System::Byte> __fastcall GetHMACAsBytes(const System::DynamicArray<System::Byte> AData, const System::DynamicArray<System::Byte> AKey, TSHA2Version AHashVersion = (TSHA2Version)(0x1))/* overload */;
#else /* _WIN64 */
    static System::TArray__1<System::Byte> __fastcall GetHMACAsBytes(const System::UnicodeString AData, const System::UnicodeString AKey, TSHA2Version AHashVersion = (TSHA2Version)(0x1))/* overload */;
    static System::TArray__1<System::Byte> __fastcall GetHMACAsBytes(const System::UnicodeString AData, const System::TArray__1<System::Byte> AKey, TSHA2Version AHashVersion = (TSHA2Version)(0x1))/* overload */;
    static System::TArray__1<System::Byte> __fastcall GetHMACAsBytes(const System::TArray__1<System::Byte> AData, const System::UnicodeString AKey, TSHA2Version AHashVersion = (TSHA2Version)(0x1))/* overload */;
    static System::TArray__1<System::Byte> __fastcall GetHMACAsBytes(const System::TArray__1<System::Byte> AData, const System::TArray__1<System::Byte> AKey, TSHA2Version AHashVersion = (TSHA2Version)(0x1))/* overload */;
#endif /* _WIN64 */
private:
    TSHA2Version FVersion;
    union
    {
        struct
        {
            System::StaticArray<unsigned __int64, 8> FHash64;
        };
        struct
        {
            System::StaticArray<unsigned, 8> FHash;
        };
    };
};

プロパティ

種類 可視性 ソース ユニット
record
struct
public
System.Hash.pas
System.Hash.hpp
System.Hash System.Hash


説明

SHA-2 ハッシュを実装するレコードです。

THashSHA2 には、以下のようなメソッドが用意されています。

  • Update: 渡されたデータを使ってハッシュ値を更新します。
  • GetHashString: 渡された文字列のハッシュ値を返します。
  • GetHashStringFromFile: 提供されたファイルのハッシュ値を返します。
  • GetHMAC: HMAC 認証(ハッシュベース メッセージ認証符号)に関連付けられた文字列表現を返します。

関連項目