CryptUtil.java revision f97667c80d9dd8155ff61164f82b9ad6deae5d95
/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2008 Sun Microsystems Inc. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* $Id: CryptUtil.java,v 1.2 2008/06/25 05:43:28 qcheng Exp $
*
*/
/*
* Portions Copyrighted [2011] [ForgeRock AS]
*/
public class CryptUtil {
static final String DEFAULT_PBE_PWD =
"KmhUnWR1MYWDYW4xuqdF5nbm+CXIyOVt";
private static final String CRYPTO_DESCRIPTOR =
"PBEWithMD5AndDES";
private static final String KEYGEN_ALGORITHM =
"PBEWithMD5AndDES";
private static final int ITERATION_COUNT = 5;
private static final byte[] ___y = {
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01
};
static private boolean _initialized = false;
private static PBEParameterSpec pbeParameterSpec =
/**
* Method declaration
*
* @param clearText
*/
// BASE64 encode the data
// Serialize the data, i.e., remove \n and \r
try {
}
} catch (IOException ioe) {
}
}
/**
* Method declaration
*
* @param encText
*/
}
// BASE64 decode the data
// Decrypt the data
}
// Convert to String and return
return answer;
}
/**
* Method declaration
*
* @param clearText
*/
static private byte[] pbeEncrypt(byte[] clearText) {
return null;
}
if (_initialized) {
try {
try {
if (ex instanceof NoSuchAlgorithmException ||
ex instanceof NoSuchPaddingException)
{
//Best effort try dynamically registring the SunJCE provider
} else {
throw ex;
}
}
} else {
}
}
} else {
}
return result;
}
/**
* Method declaration
*
* @param cipherText
*/
static private byte[] pbeDecrypt(byte[] cipherText) {
if (_initialized) {
try {
byte share[] = cipherText;
try {
if (ex instanceof NoSuchAlgorithmException ||
ex instanceof NoSuchPaddingException)
{
//Best effort try dynamically registring the SunJCE provider
} else {
throw ex;
}
}
} else {
}
}
} else {
}
return result;
}
//****************************************************
//****************************************************
//
// code characters for values 0..63
//
static private char[] alphabet =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
.toCharArray();
//
// lookup table for converting base64 characters to value in range 0..63
//
static private byte[] codes = new byte[256];
static {
}
/**
* Returns a String of base64-encoded characters to represent the
* passed data array.
*
* @param data the array of bytes to encode
* @return String base64-coded characters
*/
//
// 3 bytes encode to 4 chars. Output is always an even
// multiple of 4 characters.
//
boolean quad = false;
boolean trip = false;
val <<= 8;
trip = true;
}
val <<= 8;
quad = true;
}
val >>= 6;
val >>= 6;
val >>= 6;
}
}
/**
* Returns an array of decoded bytes which were encoded in the passed
* byte array.
*
* @param encdata the array of base64-encoded characters
* @return byte[] the decoded data array
*/
// convert to a char[]
throw new RuntimeException("Invalid encoded data!");
// check that length is a multiple of 4
throw new RuntimeException("Data is not Base64 encoded.");
int index = 0;
}
}
else
{
throw new RuntimeException("Data is not Base64 encoded.");
}
}
}
throw new RuntimeException("Data length mismatch.");
return out;
}
try {
pbeKey =
_initialized = true;
} catch (Exception e) {
}
}
//****************************************************
// Testing Main program
//****************************************************
// *******************************************
// Encrypting the data ...
// *******************************************
password);
// *******************************************
// Decrypting the data
// *******************************************
}
}