Skip to content

Latest commit

 

History

History
54 lines (36 loc) · 1.58 KB

Use.md

File metadata and controls

54 lines (36 loc) · 1.58 KB

How to use

This library provides three classes:

  • AESKW\A128KW: AES 128 key wrap
  • AESKW\A192KW: AES 192 key wrap
  • AESKW\A256KW: AES 256 key wrap

Wrap a key using RFC3394

In the following example, we will wrap the key key using the KEK kek and AES 128:

<?php

// We use the AES 128 algorithm
use AESKW\A128KW;

// The Key Encryption Key
$kek  = hex2bin("000102030405060708090A0B0C0D0E0F");

// The key we want to wrap
$key  = hex2bin("00112233445566778899AABBCCDDEEFF");

// We wrap the key
$wrapped_key = A128KW::wrap($kek, $key); // Must return "1FA68B0A8112B447AEF34BD8FB5A7B829D3E862371D2CFE5"

// We unwrap the key
$unwrapped_key = A128KW::unwrap($kek, $wrapped_key); // The result must be the same value as the key

Wrap a key using RFC5649

In the following example, we will wrap the key key using the KEK kek using AES 128. The main difference with the RFC3394 is that you can wrap a key of any practical size:

<?php

// We use the AES 128 algorithm
use AESKW\A128KW;

// The Key Encryption Key
$kek  = hex2bin("000102030405060708090A0B0C0D0E0F");

// The key we want to wrap. Please note that the size is not exactly a 64 bits-block
$key  = hex2bin("0011223344");

// We wrap the key. Please note that the third parameter enable the key padding (RFC6549)
$wrapped_key = A128KW::wrap($kek, $key, true); // Must return "9E53E571ED4669A51A4B8724788F8C80"

// We unwrap the key. Please note that the third parameter enable the key padding (RFC6549)
$unwrapped_key = A128KW::unwrap($kek, $wrapped_key, true); // The result must be the same value as the key