001: // @(#)SessionKey.java 1.9 "@(#)SessionKey.java 1.9 99/09/23 Sun Microsystems"
002:
003: package com.sun.portal.netlet.econnection;
004:
005: public class SessionKey implements KeyConstants {
006:
007: protected byte[] eKey = new byte[SESSION_KEYLEN];
008:
009: protected int eKeyLen = SESSION_KEYLEN;
010:
011: final private int exportKeyLen = 5;
012:
013: public SessionKey() {
014: this (INIT_SESSION_KEY.getBytes());
015: }
016:
017: public SessionKey(byte[] key) {
018: System.arraycopy(eKey, 0, key, 0, eKey.length);
019: }
020:
021: /*
022: * Added for bug 4432831 Decodes the Session Key from the given String @
023: * date 23-09-2001 @ added Rajesh T
024: */
025:
026: public SessionKey(String encKey) {
027: byte encodedKey[] = new byte[encKey.length()];
028: encodedKey = encKey.getBytes();
029: byte[] decodedKey = Base64.decode(encodedKey);
030:
031: if (encKey.length() != 0) {
032: eKey[0] = decodedKey[5];
033: eKey[1] = decodedKey[0];
034: eKey[2] = decodedKey[3];
035: eKey[3] = decodedKey[1];
036: eKey[4] = decodedKey[7];
037: eKey[5] = decodedKey[9];
038: eKey[6] = decodedKey[10];
039: eKey[7] = decodedKey[25];
040: eKey[8] = decodedKey[12];
041: eKey[9] = decodedKey[13];
042: eKey[10] = decodedKey[14];
043: eKey[11] = decodedKey[20];
044: eKey[12] = decodedKey[16];
045: eKey[13] = decodedKey[17];
046: eKey[14] = decodedKey[8];
047: eKey[15] = decodedKey[24];
048: eKey[16] = decodedKey[38];
049: eKey[17] = decodedKey[42];
050: eKey[18] = decodedKey[26];
051: eKey[19] = decodedKey[40];
052: eKey[20] = decodedKey[34];
053: eKey[21] = decodedKey[28];
054: eKey[22] = decodedKey[32];
055: eKey[23] = decodedKey[27];
056: eKey[24] = decodedKey[35];
057: eKey[25] = decodedKey[31];
058: eKey[26] = decodedKey[30];
059: eKey[27] = decodedKey[50];
060: eKey[28] = decodedKey[44];
061: eKey[29] = decodedKey[61];
062: eKey[30] = decodedKey[58];
063: eKey[31] = decodedKey[48];
064:
065: /*
066: * eKey[0] = decodedKey[5]; eKey[1] = decodedKey[0]; eKey[2] =
067: * decodedKey[3]; eKey[3] = decodedKey[1]; eKey[4] = decodedKey[7];
068: *
069: * if(KeyConstants.SESSION_KEYLEN > 5){ eKey[5] = decodedKey[9];
070: * eKey[6] = decodedKey[10]; eKey[7] = decodedKey[25]; eKey[8] =
071: * decodedKey[12]; eKey[9] = decodedKey[13]; eKey[10] =
072: * decodedKey[14]; eKey[11] = decodedKey[20]; eKey[12] =
073: * decodedKey[16]; eKey[13] = decodedKey[17]; eKey[14] =
074: * decodedKey[8]; eKey[15] = decodedKey[24]; }
075: */
076: }
077: }
078:
079: public byte[] getSessionKey() {
080: byte[] key = new byte[eKey.length];
081: System.arraycopy(eKey, 0, key, 0, eKey.length);
082: return (key);
083: }
084:
085: public byte[] getSessionKey(int keyLength) {
086: if (keyLength > 32)
087: keyLength = keyLength / 8;
088: byte[] key = new byte[keyLength];
089: System.arraycopy(eKey, 0, key, 0, keyLength);
090: return (key);
091: }
092:
093: public int getSessionKeyLen() {
094: return (eKeyLen);
095: }
096:
097: public void setSessionKey(byte[] k) {
098: System.arraycopy(k, 0, eKey, 0, eKey.length);
099: }
100:
101: }
|