Click here to Skip to main content
15,886,664 members
Articles / Programming Languages / XML

RFC3394 Key-wrapping Algorithm in C#

Rate me:
Please Sign up or sign in to vote.
4.80/5 (9 votes)
31 Oct 2008Public Domain3 min read 42.9K   1.7K   25  
An implementation of the RFC3394 AES key-wrapping algorithm.
using System;
using System.Security.Cryptography;
using System.Runtime.Remoting.Metadata.W3cXsd2001;
using NUnit.Framework;

namespace RFC3394.Tests
{
   [TestFixture]
   public class KWA_IntegrityTests
   {
      [Test]
      [ExpectedException(typeof(CryptographicException))]
      public void MangledCiphertext()
      {
         string kek = "000102030405060708090A0B0C0D0E0F";
         string pt = "00112233445566778899AABBCCDDEEFF";

         byte[] key = SoapHexBinary.Parse(kek).Value;
         byte[] input = SoapHexBinary.Parse(pt).Value;
         byte[] output = KeyWrapAlgorithm.WrapKey(key, input);

         output[0] ^= 0x01;  // mangle the ciphertext

         KeyWrapAlgorithm.UnwrapKey(key, output);
      }
   }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication


Written By
Architect DigiData Corp.
United States United States
Not much to tell, really!

Comments and Discussions