|
/**
* TripleDESKeyTest
*
* A test class for TripleDESKey
* Copyright (c) 2007 Henri Torgemane
*
* See LICENSE.txt for full license information.
*/
package com.hurlant.crypto.tests
{
import com.hurlant.crypto.symmetric.TripleDESKey;
import com.hurlant.util.Hex;
import flash.utils.ByteArray;
import com.hurlant.crypto.symmetric.ICipher;
import com.hurlant.crypto.symmetric.ECBMode;
public class TripleDESKeyTest extends TestCase
{
public function TripleDESKeyTest(h:ITestHarness)
{
super(h, "Triped Des Test");
runTest(testECB,"Triple DES ECB Test Vectors");
h.endTestCase();
}
/**
* Lots of vectors at http://csrc.nist.gov/publications/nistpubs/800-20/800-20.pdf
* XXX move them in here.
*/
public function testECB():void {
var keys:Array = [
"010101010101010101010101010101010101010101010101",
"dd24b3aafcc69278d650dad234956b01e371384619492ac4",
];
var pts:Array = [
"8000000000000000",
"F36B21045A030303",
];
var cts:Array = [
"95F8A5E5DD31D900",
"E823A43DEEA4D0A4",
];
for (var i:uint=0;i<keys.length;i++) {
var key:ByteArray = Hex.toArray(keys[i]);
var pt:ByteArray = Hex.toArray(pts[i]);
var ede:TripleDESKey = new TripleDESKey(key);
ede.encrypt(pt);
var out:String = Hex.fromArray(pt).toUpperCase();
assert("comparing "+cts[i]+" to "+out, cts[i]==out);
// now go back to plaintext
ede.decrypt(pt);
out = Hex.fromArray(pt).toUpperCase();
assert("comparing "+pts[i]+" to "+out, pts[i]==out);
}
}
}
}
|
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.
I currently hold the following qualifications (amongst others, I also studied Music Technology and Electronics, for my sins)
- MSc (Passed with distinctions), in Information Technology for E-Commerce
- BSc Hons (1st class) in Computer Science & Artificial Intelligence
Both of these at Sussex University UK.
Award(s)
I am lucky enough to have won a few awards for Zany Crazy code articles over the years
- Microsoft C# MVP 2016
- Codeproject MVP 2016
- Microsoft C# MVP 2015
- Codeproject MVP 2015
- Microsoft C# MVP 2014
- Codeproject MVP 2014
- Microsoft C# MVP 2013
- Codeproject MVP 2013
- Microsoft C# MVP 2012
- Codeproject MVP 2012
- Microsoft C# MVP 2011
- Codeproject MVP 2011
- Microsoft C# MVP 2010
- Codeproject MVP 2010
- Microsoft C# MVP 2009
- Codeproject MVP 2009
- Microsoft C# MVP 2008
- Codeproject MVP 2008
- And numerous codeproject awards which you can see over at my blog