CryptoSys API Library Manual

Example: Cipher.KeyUnwrap  Cipher.KeyWrap 

[VB6 equivalent: CIPHER_KeyWrap]

Dim abWK() As Byte
Dim abKeyData() As Byte
Dim abKek() As Byte

abKeyData = Cnv.FromHex("00112233 44556677 8899aabb ccddeeff")
abKek = Cnv.FromHex("c17a44e8 e28d7d64 81d1ddd5 0a3b8914")

Console.WriteLine("INPUT:")
Console.WriteLine("KEK=" & Cnv.ToHex(abKek))
Console.WriteLine("KD =" & Cnv.ToHex(abKeyData))
Console.WriteLine("OUTPUT:")

abWK = Cipher.KeyWrap(abKeyData, abKek, CipherAlgorithm.Aes128)
Console.WriteLine("WK{AES-128}=" & Cnv.ToHex(abWK))

abKeyData = Cnv.FromHex("8cbedec4 8d063e1b a46be8e3 69a9c398 d8e30ee5 42bc347c 4f30e928 ddd7db49")
abKek = Cnv.FromHex("9e84ee99 e6a84b50 c76cd414 a2d2ec05 8af41bfe 4bf3715b f894c8da 1cd445f6")

abWK = Cipher.KeyWrap(abKeyData, abKek, CipherAlgorithm.Aes256)
Console.WriteLine("WK{AES-256}=" & Cnv.ToHex(abWK))

abKeyData = Cnv.FromHex("84e7f2d8 78f89fcc cd2d5eba fc56daf7 3300f27e f771cd68")
abKek = Cnv.FromHex("8ad8274e 56f46773 8edd83d4 394e5e29 af7c4089 e4f8d9f4")

Console.WriteLine("INPUT:")
Console.WriteLine("KEK=" & Cnv.ToHex(abKek))
Console.WriteLine("KD =" & Cnv.ToHex(abKeyData))
Console.WriteLine("OUTPUT:")

abWK = Cipher.KeyWrap(abKeyData, abKek, CipherAlgorithm.Tdea)
Console.WriteLine("WK(3DES}=" & Cnv.ToHex(abWK))

' Now unwrap (decrypt)...
Console.WriteLine("Unwrap...")
Console.WriteLine("INPUT:")
Console.WriteLine("ALG=3DES")
Console.WriteLine("KEK=" & Cnv.ToHex(abKek))
Console.WriteLine("WK =" & Cnv.ToHex(abWK))
' In this case, we know that the Triple DES key will be exactly 24 bytes long, so
abKeyData = Cipher.KeyUnwrap(abWK, abKek, CipherAlgorithm.Tdea)
Console.WriteLine("OUTPUT:")
Console.WriteLine("KD =" & Cnv.ToHex(abKeyData))
Console.WriteLine("OK =84E7F2D878F89FCCCD2D5EBAFC56DAF73300F27EF771CD68")

See Also:
Cipher.KeyWrap Method

[Contents] [Index]

[PREV: Example: Blowfish.Dispose ...]   [Contents]   [Index]   
   [NEXT: Example: Cipher.KeyUnwrap ...]

Copyright © 2001-23 D.I. Management Services Pty Ltd. All rights reserved. Generated 2023-05-20T13:01:10Z.