Top Fields Constructors Methods
org.apache.derby.client.am

public Class EncryptionManager

extends Object
Class Inheritance
Imports
java.math.BigInteger, java.security.GeneralSecurityException, .Key, .KeyFactory, .KeyPair, .KeyPairGenerator, .MessageDigest, .NoSuchAlgorithmException, .NoSuchProviderException, .Provider, .PublicKey, .SecureRandom, .Security, javax.crypto.BadPaddingException, .Cipher, .IllegalBlockSizeException, .KeyAgreement, .NoSuchPaddingException, .SecretKeyFactory, javax.crypto.interfaces.DHPublicKey, javax.crypto.spec.DESKeySpec, .DHParameterSpec, .DHPublicKeySpec, .IvParameterSpec, .SecretKeySpec, org.apache.derby.shared.common.reference.SQLState, org.apache.derby.shared.common.sanity.SanityManager

Field Summary

Modifier and TypeField and Description
private transient Agent
private static final BigInteger
private static final byte[]
private static final int
private static final 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 MessageDigest
private static final BigInteger
private static final byte[]
private DHParameterSpec
private Provider
private String
private byte[]
private static final byte[]
private static final int
private SecretKeyFactory
private SecureRandom
public static final String
private static final String
private byte[]

Constructor Summary

AccessConstructor and Description
public
public
EncryptionManager(Agent agent, String algorithm)

Method Summary

Modifier and TypeMethod and Description
private byte[]
calculateEncryptionToken(int securityMechanism, byte[] initVector)

public byte[]
decryptData(byte[] cipherText, int securityMechanism, byte[] initVector, byte[] targetPublicKey)

public byte[]
encryptData(byte[] plainText, int securityMechanism, byte[] initVector, byte[] targetPublicKey)

private byte[]
generatePrivateKey(byte[] targetPublicKey)

public byte[]

Returns:

a random 8-Byte seed.
generateSeed
()

This method generates an 8-Byte random seed for the client (source).

private void
keyParityCheck(byte[] key)

public byte[]
public void
public byte[]

Returns:

a password substitute.
substitutePassword
(String
The user's name
userName
,
String
The user's password
password
,
byte[]
random client seed (RDs)
sourceSeed_
,
byte[]
random server seed (RDr)
targetSeed_
)

Strong Password Substitution (USRSSBPWD).

private byte[]

Returns:

the byte[] (with hexadecimal 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.

private 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 hexadecimal format.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

agent_back to summary
private transient Agent agent_
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 final 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_
messageDigestback to summary
private MessageDigest messageDigest
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_
providerback to summary
private Provider provider
providerNameback to summary
private String providerName
secKey_back to summary
private byte[] secKey_
SECMEC_USRSSBPWD_PWDSEQSback to summary
private static final byte[] SECMEC_USRSSBPWD_PWDSEQS
SECMEC_USRSSBPWD_SEED_LENback to summary
private static final int SECMEC_USRSSBPWD_SEED_LEN
secretKeyFactory_back to summary
private SecretKeyFactory secretKeyFactory_
secureRandomback to summary
private SecureRandom secureRandom
SHA_1_DIGEST_ALGORITHMback to summary
public static final String SHA_1_DIGEST_ALGORITHM
SHA_1_PRNG_ALGORITHMback to summary
private static final String SHA_1_PRNG_ALGORITHM
token_back to summary
private byte[] token_

Constructor Detail

EncryptionManagerback to summary
public EncryptionManager(Agent agent) throws SqlException
EncryptionManagerback to summary
public EncryptionManager(Agent agent, String algorithm) throws SqlException

Method Detail

calculateEncryptionTokenback to summary
private byte[] calculateEncryptionToken(int securityMechanism, byte[] initVector)
decryptDataback to summary
public byte[] decryptData(byte[] cipherText, int securityMechanism, byte[] initVector, byte[] targetPublicKey) throws SqlException
encryptDataback to summary
public byte[] encryptData(byte[] plainText, int securityMechanism, byte[] initVector, byte[] targetPublicKey) throws SqlException
generatePrivateKeyback to summary
private byte[] generatePrivateKey(byte[] targetPublicKey) throws SqlException
generateSeedback to summary
public byte[] generateSeed()

This method generates an 8-Byte random seed for the client (source).

Returns:byte[]

a random 8-Byte seed.

keyParityCheckback to summary
private void keyParityCheck(byte[] key) throws SqlException
obtainPublicKeyback to summary
public byte[] obtainPublicKey()
resetSecurityKeysback to summary
public void resetSecurityKeys()
substitutePasswordback to summary
public byte[] substitutePassword(String userName, String password, byte[] sourceSeed_, byte[] targetSeed_) throws SqlException

Strong Password Substitution (USRSSBPWD). This method generates a password substitute to send to the target server. Substitution algorithm works as follow: PW_TOKEN = SHA-1(PW, ID) The password (PW) and user name (ID) can be of any length greater than or equal to 1 byte. The client generates a 20-byte password substitute (PW_SUB) as follows: PW_SUB = SHA-1(PW_TOKEN, RDr, RDs, ID, PWSEQs) w/ (RDs) as the random client seed and (RDr) as the server one. See PWDSSB - Strong Password Substitution Security Mechanism (DRDA Vol.3 - P.650)

Parameters
userName:String

The user's name

password:String

The user's password

sourceSeed_:byte[]

random client seed (RDs)

targetSeed_:byte[]

random server seed (RDr)

Returns:byte[]

a password substitute.

Exceptions
SqlException:
on error
toHexByteback to summary
private 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 hexadecimal (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 hexadecimal format) form of the string (str)

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

Convert a byte array to a String with a hexadecimal format. The String may be converted back to a byte array using fromHexString.
For each byte (b) two characters are generated, the first character represents the high nibble (4 bits) in hexadecimal (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