|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectotie.security.SecurityManager
Title: SecurityManager
Description: The security manager acts both as a library class and as a wrapper class for centralizing security functionalities. The library functions can be used e.g. to encrypt and decrypt strings and to calculate message digests. The wrapping class provides a way to define the used algorithms (and passwords) in a separate metadata file (XML) and thus to change the functionality of the class on-the-fly.
Copyright: Copyright (c) Petteri Nurmi 2004
Company: Helsinki Insitute for Information Technology HIIT/BRU 2004
Field Summary | |
private java.lang.String |
AlgorithmString
The AlgorithmString attribute describes the algorithm that is to be used. |
private sun.misc.BASE64Decoder |
bDec
A decoder for transforming the contents of an encrypted string into a screen-friendly format. |
private sun.misc.BASE64Encoder |
bEnc
A encoder for transforming the contents of an encrypted string into a screen-friendly format. |
private java.lang.String |
encoding
The encoding attribute defines the character encoding scheme that is used to map the encrypted strings into screen-friendly string. |
private byte[] |
IV_BYTES
Random bytes that are used to create the initialization vector. |
private javax.crypto.spec.IvParameterSpec |
iVector
The IvParameterSpec describes the initialization vector spefication. |
private byte[] |
KEY_BYTES
Random bytes used when generating new keys. |
private java.security.KeyPair |
keyPair
The initially generated random public/private key pair for asymmetric encryption. |
private static byte[] |
salt
The salt used in crypting operations. |
private javax.crypto.Cipher |
symmetricCipher
The Cipher object stays always the same so it is rational to implement it as a separate attribute |
private javax.crypto.SecretKey |
symmetricKey
The random key that is used for symmetric encryption within this object. |
Constructor Summary | |
SecurityManager()
The default constructor. |
Method Summary | |
private void |
createArrays()
A method that initializes the byte[] arrays used for encryption. |
java.lang.String |
Decrypt(java.lang.String text)
Decrypts a given String using the key value generated in the constuctor call. |
java.lang.String |
Encrypt(java.lang.String text)
A method for encoding a given String using symmetric encryption. |
static javax.crypto.SecretKey |
getPBESecretKey(java.lang.String material)
A method for generating a secret key from the given key material. |
static java.lang.String |
MD5Digest(java.lang.String text)
A method for generating a MD5 digest for a given string. |
static java.lang.String |
PBEDecode(java.lang.String cipherText,
javax.crypto.SecretKey sKey)
A method for performing password based decryption using a PBE key. |
static java.lang.String |
PBEEncode(java.lang.String text,
javax.crypto.SecretKey sKey)
A method for performing password based encryption using a PBE key. |
static java.lang.String |
SHADigest(java.lang.String text)
A method for generating a SHA digest for a given string. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static byte[] salt
private byte[] KEY_BYTES
private byte[] IV_BYTES
private javax.crypto.Cipher symmetricCipher
private javax.crypto.spec.IvParameterSpec iVector
private javax.crypto.SecretKey symmetricKey
private java.security.KeyPair keyPair
private sun.misc.BASE64Encoder bEnc
private sun.misc.BASE64Decoder bDec
private java.lang.String AlgorithmString
private java.lang.String encoding
Constructor Detail |
public SecurityManager() throws java.security.NoSuchAlgorithmException, java.security.spec.InvalidKeySpecException, javax.crypto.NoSuchPaddingException
java.security.NoSuchAlgorithmException
- An error occurred when loading the
encryption algorithm. Most probably this is due to an old JCE version as
the functionality has been designed for Java SDK versions 1.4 and higher.
java.security.spec.InvalidKeySpecException
- The key specification that is used inside
the constructor has an error.
javax.crypto.NoSuchPaddingException
- The default padding scheme is not supported
by the system. Either change the padding scheme or install approriate JCE
extensions.Method Detail |
public static javax.crypto.SecretKey getPBESecretKey(java.lang.String material) throws java.security.NoSuchAlgorithmException, java.security.spec.InvalidKeySpecException
material
- String The key material from which the key is to be
constructed.
java.security.NoSuchAlgorithmException
- The system configuration is false and the
requested encryption algorithm is not available.
java.security.spec.InvalidKeySpecException
- Creating a key specification from the given
material failed due to, e.g., invalid key material.public static java.lang.String PBEEncode(java.lang.String text, javax.crypto.SecretKey sKey) throws java.security.NoSuchAlgorithmException, javax.crypto.NoSuchPaddingException, java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException, javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException
text
- String The string that is to be encoded.sKey
- SecretKey The secret key for
java.security.NoSuchAlgorithmException
- The operating systems does not have the
proper JCE installed.
javax.crypto.NoSuchPaddingException
- The padding defined for the cipher
algorithm is invalid.
java.security.InvalidKeyException
- The secret key is invalid, i.e., it is of
wrong type.
java.security.InvalidAlgorithmParameterException
- The parameters speficied for
the algorithm are faulty.
javax.crypto.IllegalBlockSizeException
- The block size used with the algorithm
is invalid.
javax.crypto.BadPaddingException
- The padding of the cipher resulted in an
invalid String.public static java.lang.String PBEDecode(java.lang.String cipherText, javax.crypto.SecretKey sKey) throws java.security.NoSuchAlgorithmException, javax.crypto.NoSuchPaddingException, java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException, javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException
cipherText
- String The string that is to be decoded.sKey
- SecretKey The secret key for
java.security.NoSuchAlgorithmException
- The operating systems does not have the
proper JCE installed.
javax.crypto.NoSuchPaddingException
- The padding defined for the cipher
algorithm is invalid.
java.security.InvalidKeyException
- The secret key is invalid, i.e., it is of
wrong type.
java.security.InvalidAlgorithmParameterException
- The parameters speficied for
the algorithm are faulty.
javax.crypto.IllegalBlockSizeException
- The block size used with the algorithm
is invalid.
javax.crypto.BadPaddingException
- The padding of the cipher resulted in an
invalid String.public static java.lang.String MD5Digest(java.lang.String text) throws java.security.NoSuchAlgorithmException
text
- String The String to be hashed.
java.security.NoSuchAlgorithmException
- The installed Java SDK does not support
the MD5 algorithm for some reason. Most probably this means that the SDK
does not have a cryptographic extension installed to it.public static java.lang.String SHADigest(java.lang.String text) throws java.security.NoSuchAlgorithmException
text
- String The String to be hashed.
java.security.NoSuchAlgorithmException
- The installed Java SDK does not support
the SHA-1 algorithm for some reason. Most probably this means that the SDK
does not have a cryptographic extension installed to it.public java.lang.String Encrypt(java.lang.String text) throws java.security.InvalidKeyException, javax.crypto.BadPaddingException, javax.crypto.IllegalBlockSizeException, java.security.InvalidAlgorithmParameterException, java.io.UnsupportedEncodingException
text
- String The String to be encoded.
java.security.InvalidKeyException
- The key generated in the constructor is
corrupted and encryption is impossible.
javax.crypto.BadPaddingException
- The padding of the Block is erroneous. Either
this results from a system failure or the String is corrupted.
javax.crypto.IllegalBlockSizeException
- The defined block size to be used with
the algorithm is invalid.
java.security.InvalidAlgorithmParameterException
- The parameters of the algorithm
are invalud. Either the byte values have invalid entries or something was
wrong in the initialization of the algorithm.
java.io.UnsupportedEncodingException
- The character-encoding described in
the encoding parameter is invalid.public java.lang.String Decrypt(java.lang.String text) throws java.security.InvalidKeyException, javax.crypto.BadPaddingException, javax.crypto.IllegalBlockSizeException, java.security.InvalidAlgorithmParameterException, java.io.UnsupportedEncodingException, java.io.IOException
text
- String The cipher text.
java.security.InvalidKeyException
- The key generated in the constructor is
corrupted and encryption is impossible.
javax.crypto.BadPaddingException
- The padding of the Block is erroneous. Either
this results from a system failure or the String is corrupted.
javax.crypto.IllegalBlockSizeException
- The defined block size to be used with
the algorithm is invalid.
java.security.InvalidAlgorithmParameterException
- The parameters of the algorithm
are invalud. Either the byte values have invalid entries or something was
wrong in the initialization of the algorithm.
java.io.UnsupportedEncodingException
- The character-encoding described in
the encoding parameter is invalid.
java.io.IOException
- Failure when reading the stream buffer (Cipher).private void createArrays()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |