/** * self-test routine for AES cipher * * @param hkey key to test in hex * @param hplain plaintext to test in hex * @param hcipher ciphertext to test in hex * @param lev trace level to use */ public static void self_test(String hkey, String hplain, String hcipher, int lev) { // AES test triple (128-bit key test value from FIPS-197) byte[] key = Util.hex2byte(hkey); byte[] plain = Util.hex2byte(hplain); byte[] cipher = Util.hex2byte(hcipher); byte[] result; AesAlgorithm testAES = new AesAlgorithm(); // create new AES instance to test triple testAES.traceLevel = lev; // select level of trace info testAES.setKey(key); // set key and display trace info System.out.print(testAES.traceInfo); result = testAES.encrypt(plain); // test encryption System.out.print(testAES.traceInfo); if (Arrays.equals(result, cipher)) System.out.print("Test OKn"); else System.out.print("Test Failed. Result was " + Util.toHEX(result) + "n"); result = testAES.decrypt(cipher); // test decryption System.out.print(testAES.traceInfo); if (Arrays.equals(result, plain)) System.out.print("Test OKn"); else System.out.print("Test Failed. Result was " + Util.toHEX(result) + "n"); System.out.println(); }
public void setKey(String key) { // System.out.println("CRYPT KEY IS "+key); setKey(static_stringToByteArray(key)); }