PDFium Delphi Component Docs

FPdfAes ユニット

ユニット: FPdfAes
キー展開、単一ブロックの暗号化/復号、および PDF 暗号化ハンドラが使用する AES-256-CBC ストリームラッパーを備えた Pure-Pascal の AES-128 および AES-256 ブロック暗号です

構文

TAesBlock = array[0..15] of Byte;
TAes128Key = array[0..15] of Byte;
TAes128ExpandedKey = array[0..175] of Byte;
TAes256Key = array[0..31] of Byte;
TAes256ExpandedKey = array[0..239] of Byte;

procedure Aes128KeyExpansion(const Key: TAes128Key; var Expanded: TAes128ExpandedKey);
procedure Aes128EncryptBlock(const Expanded: TAes128ExpandedKey;
  const Input: TAesBlock; var Output: TAesBlock);
procedure Aes256KeyExpansion(const Key: TAes256Key; var Expanded: TAes256ExpandedKey);
procedure Aes256EncryptBlock(const Expanded: TAes256ExpandedKey;
  const Input: TAesBlock; var Output: TAesBlock);
procedure Aes256DecryptBlock(const Expanded: TAes256ExpandedKey;
  const Input: TAesBlock; var Output: TAesBlock);
function Aes256CbcEncryptPKCS7(const Key: TAes256Key; const IV: TAesBlock;
  const Plain: TBytes): TBytes;
function Aes256CbcEncryptNoPad(const Key: TAes256Key; const IV: TAesBlock;
  const Plain: TBytes): TBytes;
function Aes256CbcDecryptPKCS7(const Key: TAes256Key; const IV: TAesBlock;
  const Cipher: TBytes): TBytes;
function Aes256CbcDecryptNoPad(const Key: TAes256Key; const IV: TAesBlock;
  const Cipher: TBytes): TBytes;
function Aes256KeyWrap(const KeyEncryptionKey: TAes256Key;
  const PlainKeyData: TBytes): TBytes;
function Aes256KeyUnwrap(const KeyEncryptionKey: TAes256Key; const WrappedKeyData: TBytes;
  out PlainKeyData: TBytes): Boolean;
procedure AesGenerateRandomBytes(Buffer: Pointer; Count: Integer);

説明

FPdfAes は、外部の暗号ライブラリに依存せずに Delphi、C++Builder、Free Pascal で PDF ストリームの暗号化と復号を行えるよう用意された、依存関係のない AES 実装です。FPdfEncrypt の PDF AES-256 セキュリティハンドラと、FPdfAesGcm の GCM モードで使用されます

ブロックプリミティブは展開されたラウンドキーを用いて固定の 16 バイトブロックを処理します。CBC ラッパーは可変長バイト配列に対して PKCS#7 パディングまたはパディングなしを扱い、PDF 仕様が要求する 2 つのストリーム暗号化モードに対応します

AesGenerateRandomBytes は、IV、ソルト、キーとして使用される暗号論的にランダムなバイトでバッファを埋めます

関数

関数説明
Aes128KeyExpansion128 ビットキーを 176 バイトのラウンドキースケジュールに展開します
Aes128EncryptBlock展開済み AES-128 キーで 1 つの 16 バイトブロックを暗号化します
Aes256KeyExpansion256 ビットキーを 240 バイトのラウンドキースケジュールに展開します
Aes256EncryptBlock展開済み AES-256 キーで 1 つの 16 バイトブロックを暗号化します
Aes256DecryptBlock展開済み AES-256 キーで 1 つの 16 バイトブロックを復号します
Aes256CbcEncryptPKCS7CBC モードで PKCS#7 パディングを用いてバイト配列を暗号化します
Aes256CbcEncryptNoPadCBC モードでパディングなしにバイト配列を暗号化します (入力長はブロックの倍数でなければなりません)
Aes256CbcDecryptPKCS7CBC 暗号文を復号し PKCS#7 パディングを除去します
Aes256CbcDecryptNoPadパディングを除去せずに CBC 暗号文を復号します
Aes256KeyWrapRFC 3394 の完全性保護を用いて AES-256 でキーデータをラップします
Aes256KeyUnwrapRFC 3394 のキーデータを認証してアンラップし、完全性検証に失敗した場合は平文を返しません
AesGenerateRandomBytesバッファを暗号論的にランダムなバイトで埋めます

型

型説明
TAesBlock16 バイトの AES データブロック 1 個分。単一ブロックのプリミティブと CBC のチェーン処理の単位であり、CBC ラッパーの IV 型でもあります
TAes128KeyAes128KeyExpansion が受け付ける 16 バイトの AES-128 キー
TAes128ExpandedKeyAes128KeyExpansion が生成し Aes128EncryptBlock が受け取る 176 バイトの AES-128 ラウンドキースケジュール
TAes256KeyAes256KeyExpansion、CBC ラッパー、RFC 3394 の key-wrap 関数が受け付ける 32 バイトの AES-256 キー
TAes256ExpandedKey14 ラウンド全体をカバーする 240 バイトの AES-256 ラウンドキースケジュール。Aes256KeyExpansion が生成し、ブロック暗号化 / 復号および CBC ルーチンが受け取ります

定数

定数値説明
AES_BLOCK_SIZE16AES のブロックサイズ (バイト単位)
AES128_KEY_SIZE16AES-128 のキーサイズ (バイト単位)
AES128_ROUND_KEY_SIZE176展開済み AES-128 ラウンドキーのサイズ (バイト単位)
AES256_KEY_SIZE32AES-256 のキーサイズ (バイト単位)
AES256_ROUND_KEY_SIZE240展開済み AES-256 ラウンドキーのサイズ (バイト単位)

備考

関連項目

FPdfAesGcm, FPdfEncrypt