|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--iaik.me.security.CryptoBag
This is the central class for keying material and parameters. It is used to represent
secret keys, initialization vectors, public keys, private keys, key parameters, keypairs, etc.
Instances are created using the make*
methods defined in this class and those methods
and the constructors in the PublicKey and PrivateKey classes.
Objects of this class are immutable, i.e. they cannot be modified once they have been created.
The values contained in the object can be retrieved using the appropriate get*()
method
using one of the V_*
constants valid for the object, i.e.
getByteArray()
for byte[] values (secret keys, ivs),
getBigInteger()
for BigInteger values (RSA moduli and exponents, etc.)
getCryptoBag()
for CryptoBag values (DSA and DH parameters, etc.)
Example:
To create a secret key:
byte[] keyData = ...; // the given key as a byte array byte[] ivData = ...; // the given iv as a byte array CryptoBag key = CryptoBag.makeSecretKey(keyData); CryptoBag iv = CryptoBag.makeIv(ivData); cipher.init(Cipher.ENCRYPT_MODE, key, iv, null); // initialize a cipher object
PublicKey
,
PrivateKey
Field Summary | |
static int |
TYPE_DH_PARAMS
Type constant for Diffie-Hellman parameters. |
static int |
TYPE_DH_PRIVATE
Type constant for an Diffie-Hellman private key. |
static int |
TYPE_DH_PUBLIC
Type constant for an Diffie-Hellman public key. |
static int |
TYPE_DSA_PARAMS
Type constant for DSA parameters. |
static int |
TYPE_DSA_PRIVATE
Type constant for an DSA private key. |
static int |
TYPE_DSA_PUBLIC
Type constant for an DSA public key. |
static int |
TYPE_IV
Type constant for an initialization vector. |
static int |
TYPE_KEYPAIR
Type constant for a key pair, i.e. a public key and a private key |
static int |
TYPE_RSA_PRIVATE
Type constant for an RSA private key. |
static int |
TYPE_RSA_PUBLIC
Type constant for an RSA public key. |
static int |
TYPE_SECRET_KEY
Type constant for a secret key. |
static int |
V_DH_G
|
static int |
V_DH_P
|
static int |
V_DH_PARAMS
|
static int |
V_DH_X
|
static int |
V_DH_Y
|
static int |
V_DSA_G
|
static int |
V_DSA_P
|
static int |
V_DSA_PARAMS
|
static int |
V_DSA_Q
|
static int |
V_DSA_X
|
static int |
V_DSA_Y
|
static int |
V_IV
|
static int |
V_KEY
|
static int |
V_KEY_PRIVATE
|
static int |
V_KEY_PUBLIC
|
static int |
V_RSA_CRT_C
|
static int |
V_RSA_CRT_EP
|
static int |
V_RSA_CRT_EQ
|
static int |
V_RSA_CRT_P
|
static int |
V_RSA_CRT_Q
|
static int |
V_RSA_D
|
static int |
V_RSA_E
|
static int |
V_RSA_N
|
Constructor Summary | |
CryptoBag(ASN1 asn1)
Creates a CryptoBag from its ASN.1 object representing an DSA or DH algorithmID with parameters included. |
Method Summary | |
boolean |
equals(Object obj)
|
ASN1 |
getASN1()
Returns this CryptoBag as ASN.1 object representing an DSA or DH algorithmID with parameters included. |
BigInteger |
getBigInteger(int param)
Gets a BigInteger component out of the CryptoBag. |
byte[] |
getByteArray(int param)
Gets a byte array component out of the CryptoBag. |
CryptoBag |
getCryptoBag(int param)
Gets a CryptoBag component out of the CryptoBag. |
byte[] |
getEncoded()
Returns this CryptoBag as DER encoded byte array. |
int |
getKeyLength()
|
int |
getType()
|
int |
hashCode()
|
static CryptoBag |
makeDHParameters(BigInteger p,
BigInteger g)
Creates a CryptoBag for the given DH parameters. |
static CryptoBag |
makeDSAParameters(BigInteger p,
BigInteger q,
BigInteger g)
Creates a CryptoBag for the given DSA parameters. |
static CryptoBag |
makeIV(byte[] iv)
Creates a CryptoBag for the given initialization vector. |
static CryptoBag |
makeKeyPair(PublicKey pubKey,
PrivateKey privKey)
Creates a CryptoBag for the given key pair. |
static CryptoBag |
makeSecretKey(byte[] key)
Creates a CryptoBag for the given raw secret key encoding. |
String |
toString()
|
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int TYPE_SECRET_KEY
public static final int TYPE_IV
public static final int TYPE_RSA_PUBLIC
public static final int TYPE_RSA_PRIVATE
public static final int TYPE_DSA_PUBLIC
public static final int TYPE_DSA_PRIVATE
public static final int TYPE_DSA_PARAMS
public static final int TYPE_DH_PUBLIC
public static final int TYPE_DH_PRIVATE
public static final int TYPE_DH_PARAMS
public static final int TYPE_KEYPAIR
public static final int V_KEY
public static final int V_IV
public static final int V_RSA_N
public static final int V_RSA_E
public static final int V_RSA_D
public static final int V_RSA_CRT_P
public static final int V_RSA_CRT_Q
public static final int V_RSA_CRT_EP
public static final int V_RSA_CRT_EQ
public static final int V_RSA_CRT_C
public static final int V_DSA_X
public static final int V_DSA_Y
public static final int V_DSA_PARAMS
public static final int V_DSA_P
public static final int V_DSA_Q
public static final int V_DSA_G
public static final int V_DH_X
public static final int V_DH_Y
public static final int V_DH_PARAMS
public static final int V_DH_P
public static final int V_DH_G
public static final int V_KEY_PUBLIC
public static final int V_KEY_PRIVATE
Constructor Detail |
public CryptoBag(ASN1 asn1) throws IOException
class
PublicKey immediately.asn1
- the CryptoBag as ASN1 objectIOException
- if an parsing error occurs or
if the ASN1 object does not represent DSA or DH
parametersMethod Detail |
public ASN1 getASN1()
class
PublicKey immediately.public byte[] getEncoded()
public int getType()
public int getKeyLength()
public BigInteger getBigInteger(int param)
param
represents a BigInteger, e.g.:
BigInteger pub_exp = rsaPublicKey.getBigInteger(CryptoBag.V_RSA_E);retrieves the public exponent of an RSA public key.
the
- V_ constant referencing the BigInteger component to be retrievedpublic byte[] getByteArray(int param)
param
is represented by a byte array, e.g.:
byte[] ivData = cryptoBag.getByteArray(CryptoBag.V_IV);retrieves an initialization vector as byte array.
the
- V_ constant referencing the byte array component to be retrievedpublic CryptoBag getCryptoBag(int param)
param
represents a CryptoBag itself, e.g.:
CryptoBag keyPair = ...; PublicKey rsa_pub = (PublicKey)keyPair.getCryptoBag(CryptoBag.V_KEY_PUBLIC);retrieves the public key of an RSA key pair (note that PublicKey is a CryptoBag and therefore method getCryptoBag can be used here).
the
- V_ constant referencing the CryptoBag component to be retrievedpublic static CryptoBag makeSecretKey(byte[] key)
key
- the secret key encodingpublic static CryptoBag makeIV(byte[] iv)
iv
- the initialization vector as byte arraypublic static CryptoBag makeDSAParameters(BigInteger p, BigInteger q, BigInteger g)
p
- the public prime valueq
- the public sub-prime valueg
- the public base valuepublic static CryptoBag makeDHParameters(BigInteger p, BigInteger g)
p
- prime modulus pg
- the base generatorpublic static CryptoBag makeKeyPair(PublicKey pubKey, PrivateKey privKey)
pubKey
- the public keyprivKey
- the private keypublic boolean equals(Object obj)
equals
in class Object
public int hashCode()
hashCode
in class Object
public String toString()
toString
in class Object
|
This Javadoc may contain text parts from IETF Internet Standard specifications, see copyright note) and RSA Data Security Public-Key Cryptography Standards (see copyright note). | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |