Top Description Fields Constructors Methods
org.apache.derby.impl.drda

pack-priv Class DecryptionManager

extends Object
Class Inheritance
Imports
java.math.BigInteger, java.security.KeyFactory, .KeyPair, .KeyPairGenerator, .PublicKey, java.security.spec.AlgorithmParameterSpec, java.sql.SQLException, javax.crypto.Cipher, .KeyAgreement, javax.crypto.interfaces.DHPublicKey, javax.crypto.spec.DHParameterSpec, .DHPublicKeySpec, .IvParameterSpec, .SecretKeySpec

This class is used to decrypt password and/or userid. It uses Diffie_Hellman algorithm to get the publick key and secret key, and then DES encryption is done using certain token (based on security mechanism) and this side's own public key. Basically, this class is called when using a security mechanism that encrypts user ID and password (eusridpwd). This class uses IBM JCE to do Diffie_Hellman algorithm and DES encryption.

Field Summary

Modifier and TypeField and Description
private static final BigInteger
private static final byte[]
private static final int
private static char[]
hex_table

Resolve

* The methods and static vars below should go into some 'shared' * package when the capability is put back in (StringUtil.java).

private KeyAgreement
private KeyPair
private KeyPairGenerator
private static final BigInteger
private static final byte[]
private DHParameterSpec
private static final int
private static final String

Constructor Summary

AccessConstructor and Description
pack-priv
DecryptionManager()

EncryptionManager constructor.

Method Summary

Modifier and TypeMethod and Description
private byte[]

Returns:

byte[] the decryption token
calculateDecryptionToken
(int
security mechanism
securityMechanism
,
byte[]
userid or server(this side)'s connection key
initVector
)

This method is used to calculate the decryption token.

public byte[]

Returns:

the decrypted data (plain text) in a byte array.
decryptData
(byte[]
The byte array form userid/password to decrypt.
cipherText
,
int
security mechanism
securityMechanism
,
byte[]
The byte array which is used to calculate the decryption token for initializing the cipher
initVector
,
byte[]
application requester (encrypter)'s public key.
sourcePublicKey
)

This method generates a secret key using the application requester's public key, and decrypts the usreid/password with the middle 8 bytes of the generated secret key and a decryption token.

protected static byte[]

Returns:

a random 8-Byte seed.
generateSeed
()

This method generates an 8-Byte random seed.

public byte[]

Returns:

a byte array that is the application server's public key
obtainPublicKey
()

This method generates the public key and returns it.

protected static byte[]

Returns:

the byte[] (with hexidecimal format) form of the string (str)
toHexByte
(String
string
str
,
int
starting character (zero based) to convert.
offset
,
int
number of characters to convert.
length
)

Convert a string into a byte array in hex format.

protected static String

Returns:

the String (with hexidecimal format) form of the byte array
toHexString
(byte[]
byte array
data
,
int
starting byte (zero based) to convert.
offset
,
int
number of bytes to convert.
length
)

Convert a byte array to a String with a hexidecimal format.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

base__back to summary
private static final BigInteger base__
baseBytes__back to summary
private static final byte[] baseBytes__
exponential_length__back to summary
private static final int exponential_length__
hex_tableback to summary
private static char[] hex_table

Resolve

* The methods and static vars below should go into some 'shared' * package when the capability is put back in (StringUtil.java). *

keyAgreement_back to summary
private KeyAgreement keyAgreement_
keyPair_back to summary
private KeyPair keyPair_
keyPairGenerator_back to summary
private KeyPairGenerator keyPairGenerator_
modulus__back to summary
private static final BigInteger modulus__
modulusBytes__back to summary
private static final byte[] modulusBytes__
paramSpec_back to summary
private DHParameterSpec paramSpec_
SECMEC_USRSSBPWD_SEED_LENback to summary
private static final int SECMEC_USRSSBPWD_SEED_LEN
SHA_1_PRNG_ALGORITHMback to summary
private static final String SHA_1_PRNG_ALGORITHM

Constructor Detail

DecryptionManagerback to summary
pack-priv DecryptionManager() throws SQLException

EncryptionManager constructor. In this constructor,DHParameterSpec, KeyPairGenerator, KeyPair, and KeyAgreement are initialized.

Exceptions
SQLException:
that wraps any error

Method Detail

calculateDecryptionTokenback to summary
private byte[] calculateDecryptionToken(int securityMechanism, byte[] initVector)

This method is used to calculate the decryption token. DES encrypts the data using a token and the generated shared private key. The token used depends on the type of security mechanism being used: USRENCPWD - The userid is used as the token. The USRID is zero-padded to 8 bytes if less than 8 bytes or truncated to 8 bytes if greater than 8 bytes. EUSRIDPWD - The middle 8 bytes of the server's connection key is used as the token. Decryption needs to use exactly the same token as encryption.

Parameters
securityMechanism:int

security mechanism

initVector:byte[]

userid or server(this side)'s connection key

Returns:byte[]

byte[] the decryption token

decryptDataback to summary
public byte[] decryptData(byte[] cipherText, int securityMechanism, byte[] initVector, byte[] sourcePublicKey) throws SQLException

This method generates a secret key using the application requester's public key, and decrypts the usreid/password with the middle 8 bytes of the generated secret key and a decryption token. Then it returns the decrypted data in a byte array.

Parameters
cipherText:byte[]

The byte array form userid/password to decrypt.

securityMechanism:int

security mechanism

initVector:byte[]

The byte array which is used to calculate the decryption token for initializing the cipher

sourcePublicKey:byte[]

application requester (encrypter)'s public key.

Returns:byte[]

the decrypted data (plain text) in a byte array.

generateSeedback to summary
protected static byte[] generateSeed() throws SQLException

This method generates an 8-Byte random seed. Required for the SECMEC_USRSSBPWD security mechanism

Returns:byte[]

a random 8-Byte seed.

obtainPublicKeyback to summary
public byte[] obtainPublicKey()

This method generates the public key and returns it. This shared public key is the application server's connection key and will be exchanged with the application requester's connection key. This connection key will be put in the sectkn in ACCSECRD command and send to the application requester.

Returns:byte[]

a byte array that is the application server's public key

toHexByteback to summary
protected static byte[] toHexByte(String str, int offset, int length)

Convert a string into a byte array in hex format.
For each character (b) two bytes are generated, the first byte represents the high nibble (4 bits) in hexidecimal (b & 0xf0), the second byte represents the low nibble (b & 0x0f).
The character at str.charAt(0) is represented by the first two bytes in the returned String.

Parameters
str:String

string

offset:int

starting character (zero based) to convert.

length:int

number of characters to convert.

Returns:byte[]

the byte[] (with hexidecimal format) form of the string (str)

toHexStringback to summary
protected static String toHexString(byte[] data, int offset, int length)

Convert a byte array to a String with a hexidecimal format. The String may be converted back to a byte array using fromHexString.
For each byte (b) two characaters are generated, the first character represents the high nibble (4 bits) in hexidecimal (b & 0xf0), the second character represents the low nibble (b & 0x0f).
The byte at data[offset] is represented by the first two characters in the returned String.

Parameters
data:byte[]

byte array

offset:int

starting byte (zero based) to convert.

length:int

number of bytes to convert.

Returns:String

the String (with hexidecimal format) form of the byte array