|
|||||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |
See:
Description
Interface Summary | |
DESKeySpec | DESKeySpec interface. |
Class Summary | |
DES1KeySpec | DES secret key specification (56 bit or 64 bit with parity) class. |
DESede2KeySpec | 2 Key Triple DES secret key specification (112 bit or 128 bit with parity) class. |
DESede3KeySpec | 3 Key Triple DES secret keys specification (168 bit or 192 bit with parity) class. |
DESOperationModeInitializationVectorSpec | DES Initialization Vector (64 bit) class. |
Provides classes and interfaces for key specifications and algorithm parameter specifications.
A key specification is a transparent representation of the key material that constitutes a key. A key may be specified in an algorithm-specific way, or in an algorithm-independent encoding format.
This package contains key specifications for:
We do check every DES key specification for weak and semiweak keys while
construction from the byte array that contains the key material. So you don't
have to do this. We do all the work for you. The consequence in this
decision is that you can't construct a weak or semiweak DES key specification.
Further more - if a byte array contains key material that isn't parity adjusted, we do
that in every case for you. This means that getKey() won't return the same key material
as you put in to the constructor - if the parity of the key material wasn't
parity adjusted. For mor details look in to the private method:
DES1KeySpec.oddParity(byte[])
This package contains algorithm paramter specifications for:
All public classes in this packages support object cloneing with a
deep copy. They overides also Object.equals(java.lang.Object)
,
Object.hashCode()
and Object.toString()
.
So you can use this classes with the collection API.
The classes in this package are not Serializable
.
package com.foo.bar; import java.security.InvalidKeyException; import javax.crypto.IllegalBlockSizeException; import de.cscc.crypto.provider.spec.DESede2KeySpec; import de.cscc.crypto.provider.spec.DESOperationModeInitializationVectorSpec; public class Main { public static void main (String args[]) { //2Key Triple DES key as byte array byte[] key = { //key 1 (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67, (byte) 0x89, (byte) 0xab, (byte) 0xcd, (byte) 0xef, //key 2 (byte) 0x23, (byte) 0x45, (byte) 0x67, (byte) 0x89, (byte) 0xab, (byte) 0xcd, (byte) 0xef, (byte) 0x01 }; //Construct a 2 Key Triple DES key as DESede2KeySpec DESede2KeySpec spec = null; try { spec = new DESede2KeySpec(key); } catch (InvalidKeyException e) { e.printStackTrace(); } //get the key as byte[16] array byte[] keyAsByteArray = spec.getKey(); //clone the key DESede2KeySpec cloneSpec= null; try { cloneSpec = (DESede2KeySpec) spec.clone(); } catch(CloneNotSupportedException e) { e.printStackTrace(); } //print the keys out System.out.println("spec: " + spec); System.out.println("cloneSpec: " + cloneSpec); //Iv as byte array. byte[] byteValue = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }; //construct an DES CBC Iv from a byte[8] array DESOperationModeInitializationVectorSpec iv = null; try { iv = new DESOperationModeInitializationVectorSpec(byteValue); } catch(IllegalBlockSizeException e) { e.printStackTrace(); } //get the iv as byte[8] array byte[] ivAsByteArray = iv.getIv(); //clone the iv DESOperationModeInitializationVectorSpec cloneIv = null; try { cloneIv = (DESOperationModeInitializationVectorSpec) iv.clone(); } catch(CloneNotSupportedException e) { e.printStackTrace(); } System.out.println("iv: " + iv); System.out.println("cloneIv: " + cloneIv); } }
Output:
spec: key1: [0x0123456789abcdef] key2: [0x23456789abcdef01] cloneSpec: key1: [0x0123456789abcdef] key2: [0x23456789abcdef01] iv: 0x0000000000000000 cloneIv: 0x0000000000000000
|
|||||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |