|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectde.upb.swtpra05.group03.crypto.Crypto
This is the main Crypto class. It is used to encrypt and decrypt messages.
| Field Summary | |
protected static java.lang.String |
AGREEMENT_ALGORITHM
Algorithm used for public/private key agreement |
protected static java.lang.String |
CIPHER_ALGORITHM
Algorithm used for symmetric en-/decryption |
private javax.crypto.Cipher |
decrypter
Cipher object used for decryption |
private javax.crypto.Cipher |
encrypter
Cipher object used for encryption |
protected static java.lang.String |
KEY_ALGORITHM
Algorithm used to create the secret key |
protected java.security.KeyFactory |
pubKeyFactory
factory used to create public keys from x509 encoding |
private javax.crypto.SecretKey |
secretKey
secret key with which data is en-/decrypted |
protected static java.lang.String |
SIGNATURE_ALGORITHM
Algorithm used for signing and verifying data |
protected java.security.Signature |
signer
Signature object used for signing |
protected int |
state
holds the state of this object |
static int |
STATE_INIT
Constant for State INIT |
static int |
STATE_READY
Constant for State READY |
static int |
STATE_WAITING
Constant for State WAITING |
protected java.security.Signature |
verifyer
Signature object used for verifying signatures |
| Constructor Summary | |
Crypto()
Constructor to create the Crypto object. |
|
| Method Summary | |
java.lang.Object |
decryptObject(DataSigPair dsp)
decrypts an bytearray to an object |
DataSigPair |
encryptObject(java.io.Serializable obj)
encrypts an object |
protected java.security.PublicKey |
genPublicKeyFromX509(byte[] x509Key)
generates a public key from the bytearray in the x509 format |
byte[] |
getSecretKey()
gets the secret key |
boolean |
isReady()
if state is READY |
protected void |
loadSigningKeys(java.lang.String name)
loads public and private key with the SigningKeys class.
|
void |
reset()
reset the state to INIT so a new key agreement can be made |
void |
setSecretKey(byte[] key)
to set the secret key directly without key agreement |
protected void |
setSecretKey(javax.crypto.SecretKey secretKey)
sets the secret key directly without key agreement |
protected byte[] |
sign(byte[] data)
signs data |
protected boolean |
verify(DataSigPair dsp)
verifies signature for data |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int STATE_INIT
public static final int STATE_WAITING
public static final int STATE_READY
protected static final java.lang.String AGREEMENT_ALGORITHM
protected static final java.lang.String KEY_ALGORITHM
protected static final java.lang.String CIPHER_ALGORITHM
protected static final java.lang.String SIGNATURE_ALGORITHM
protected int state
private javax.crypto.SecretKey secretKey
private final javax.crypto.Cipher encrypter
private final javax.crypto.Cipher decrypter
protected final java.security.Signature signer
protected final java.security.Signature verifyer
protected final java.security.KeyFactory pubKeyFactory
| Constructor Detail |
public Crypto()
throws java.security.NoSuchAlgorithmException,
javax.crypto.NoSuchPaddingException
javax.crypto.NoSuchPaddingException
java.security.NoSuchAlgorithmException| Method Detail |
protected void loadSigningKeys(java.lang.String name)
throws java.security.NoSuchAlgorithmException,
java.security.spec.InvalidKeySpecException,
java.io.IOException,
java.security.InvalidKeyException
SigningKeys class.
the public key is used by the verifyer and the secret one
is used by the signer
name - have to be either "shuttle" or "company"
java.security.NoSuchAlgorithmException
java.security.spec.InvalidKeySpecException
java.io.IOException
java.security.InvalidKeyExceptionSigningKeys.loadKeys(String)
public void setSecretKey(byte[] key)
throws java.io.IOException,
java.lang.ClassNotFoundException,
java.security.InvalidKeyException
key - a bytearray of the serialized SecretKey object
java.io.IOException
java.lang.ClassNotFoundException
java.security.InvalidKeyException
protected void setSecretKey(javax.crypto.SecretKey secretKey)
throws java.security.InvalidKeyException
secretKey - the new SecretKey
java.security.InvalidKeyException
public byte[] getSecretKey()
throws java.io.IOException
java.io.IOExceptionpublic void reset()
state to INIT so a new key agreement can be made
public DataSigPair encryptObject(java.io.Serializable obj)
throws java.io.IOException,
java.security.SignatureException
obj - object wich implements Serializable
java.io.IOException
java.security.SignatureException
java.security.SignatureException
public java.lang.Object decryptObject(DataSigPair dsp)
throws java.lang.IllegalStateException,
java.io.IOException,
java.lang.ClassNotFoundException,
java.security.SignatureException
dsp - object containing data and signature
java.lang.IllegalStateException
java.io.IOException
java.lang.ClassNotFoundException
java.security.SignatureException
protected byte[] sign(byte[] data)
throws java.security.SignatureException
data - a bytearray
java.security.SignatureException
protected boolean verify(DataSigPair dsp)
throws java.security.SignatureException
dsp - object containing data and signature
java.security.SignatureExceptionpublic boolean isReady()
protected java.security.PublicKey genPublicKeyFromX509(byte[] x509Key)
throws java.security.spec.InvalidKeySpecException
x509Key - public key in the x509 format
java.security.spec.InvalidKeySpecException
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||