Project JXTA

net.jxta.impl.membership.pse
Class PSEUtils

java.lang.Object
  extended by net.jxta.impl.membership.pse.PSEUtils

public final class PSEUtils
extends Object

Singleton class of static utility methods.

Properties:

net.jxta.impl.membership.pse.PSEUtils.PBEParamsClass - if defined the name of the class which will be aliased to the OID 1.2.840.113549.1.5.3


Nested Class Summary
static class PSEUtils.IssuerInfo
          Issuer Information
static class PSEUtils.PSEProvider
          A provider we construct.
 
Field Summary
(package private) static String PKCS5_PBSE1_ALGO
          We are trying to use : PBEWithMD5AndDES
(package private)  SecureRandom srng
          A SecureRandom for generating keys.
 
Method Summary
static byte[] base64Decode(Reader in)
          Convert a BASE64 Encoded String into byte array.
static String base64Encode(byte[] in)
          Convert a byte array into a BASE64 encoded String.
static byte[] computeSignature(String algorithm, PrivateKey key, InputStream stream)
          Compute the signature of a stream.
static String findObject(BufferedReader br, String type)
           
static PSEUtils.IssuerInfo genCert(String cn, PSEUtils.IssuerInfo issuerinfo)
          Generate a Cert
static PSEUtils.IssuerInfo genCert(X500Principal subject, KeyPair keypair, PSEUtils.IssuerInfo issuerinfo)
          Generate a Cert given a keypair
static String getCertSubjectCName(X509Certificate cert)
          return the CN token from the provided cert's subjectDN
static byte[] hash(String algorithm, byte[] data)
          returns a hash SHA-1 of the given byte array
static String loadBase64Object(BufferedReader rdr, String type)
          WrappedObject.java Copyright (C) 1999, Claymore Systems, Inc.
static byte[] loadObject(BufferedReader rdr, String type)
           
static PrivateKey pkcs5_Decrypt_pbePrivateKey(char[] password, String algorithm, EncryptedPrivateKeyInfo encryptedPrivKey)
          Given an encrypted private key and a password, decrypt the private key using the PBESE1 algorithm.
static EncryptedPrivateKeyInfo pkcs5_Encrypt_pbePrivateKey(char[] password, PrivateKey privkey, int iterations)
          Given a private key and a password, encrypt the private key using the PBESE1 algorithm.
static String readBase64Object(BufferedReader br, String type)
          We read a block of n-lines (\n terminated) and return a String of n-lines concatenated together.
static byte[] readObject(BufferedReader br, String type)
          Read an object
static boolean verifySignature(String algorithm, Certificate cert, byte[] signature, InputStream stream)
          Verify a signature of a stream.
static void writeBase64Object(BufferedWriter bw, String type, String object)
          Write an ovject that is already base64 encoded.
static void writeObject(BufferedWriter out, String type, byte[] object)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

srng

final transient SecureRandom srng
A SecureRandom for generating keys.


PKCS5_PBSE1_ALGO

static final String PKCS5_PBSE1_ALGO
We are trying to use : PBEWithMD5AndDES

See Also:
Constant Field Values
Method Detail

genCert

public static PSEUtils.IssuerInfo genCert(String cn,
                                          PSEUtils.IssuerInfo issuerinfo)
                                   throws SecurityException
Generate a Cert

Parameters:
cn - subject cn for the certificate
issuerinfo - the cert issuer or null if self-signed root cert.
Returns:
the details of the generated cert.
Throws:
SecurityException - if the cert could not be generated.

genCert

public static PSEUtils.IssuerInfo genCert(X500Principal subject,
                                          KeyPair keypair,
                                          PSEUtils.IssuerInfo issuerinfo)
                                   throws SecurityException
Generate a Cert given a keypair

Parameters:
subject - subjectDN for the certificate
keypair - the keypair to use.
issuerinfo - the cert issuer or null if self-signed root cert.
Returns:
the details of the generated cert.
Throws:
SecurityException - if the cert could not be generated.

getCertSubjectCName

public static String getCertSubjectCName(X509Certificate cert)
return the CN token from the provided cert's subjectDN

Parameters:
cert - the certificate to examine
Returns:
the CN name or null if none could be found.

computeSignature

public static byte[] computeSignature(String algorithm,
                                      PrivateKey key,
                                      InputStream stream)
                               throws InvalidKeyException,
                                      SignatureException,
                                      IOException
Compute the signature of a stream.

Parameters:
key - the private key used to sign the stream
stream - the stream to sign.
Returns:
byte[] the signature
Throws:
InvalidKeyException
SignatureException
IOException

verifySignature

public static boolean verifySignature(String algorithm,
                                      Certificate cert,
                                      byte[] signature,
                                      InputStream stream)
                               throws InvalidKeyException,
                                      SignatureException,
                                      IOException
Verify a signature of a stream.

Parameters:
cert - The certificate containing the public key which will be used to verify the signature.
signature - The signature to verify.
stream - The stream to verify.
Returns:
boolean true if the signature was valid otherwise false.
Throws:
InvalidKeyException
SignatureException
IOException

hash

public static byte[] hash(String algorithm,
                          byte[] data)
returns a hash SHA-1 of the given byte array

Parameters:
data - the data to be hashed
Returns:
byte[] the hash of the data

pkcs5_Encrypt_pbePrivateKey

public static EncryptedPrivateKeyInfo pkcs5_Encrypt_pbePrivateKey(char[] password,
                                                                  PrivateKey privkey,
                                                                  int iterations)
Given a private key and a password, encrypt the private key using the PBESE1 algorithm.

Parameters:
password - The password which will be used.
privkey - The private key to be encrypted.
iterations - Number of iterations.
Returns:
An encrypted private key info or null if the key could not be encrypted.

pkcs5_Decrypt_pbePrivateKey

public static PrivateKey pkcs5_Decrypt_pbePrivateKey(char[] password,
                                                     String algorithm,
                                                     EncryptedPrivateKeyInfo encryptedPrivKey)
Given an encrypted private key and a password, decrypt the private key using the PBESE1 algorithm.

Parameters:
password - The password which will be used.
encryptedPrivKey - The private key to be encrypted.
Returns:
The decrypted private key or null if the key could not be decrpyted.

loadBase64Object

public static String loadBase64Object(BufferedReader rdr,
                                      String type)
                               throws IOException
WrappedObject.java Copyright (C) 1999, Claymore Systems, Inc. All Rights Reserved. ekr@rtfm.com Fri Jun 4 09:11:27 1999 This package is a SSLv3/TLS implementation written by Eric Rescorla and licensed by Claymore Systems, Inc. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. All advertising materials mentioning features or use of this software must display the following acknowledgement: This product includes software developed by Claymore Systems, Inc. 4. Neither the name of Claymore Systems, Inc. nor the name of Eric Rescorla may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Throws:
IOException

loadObject

public static byte[] loadObject(BufferedReader rdr,
                                String type)
                         throws IOException
Throws:
IOException

findObject

public static String findObject(BufferedReader br,
                                String type)
                         throws IOException
Throws:
IOException

readBase64Object

public static String readBase64Object(BufferedReader br,
                                      String type)
                               throws IOException
We read a block of n-lines (\n terminated) and return a String of n-lines concatenated together. This keeps the format consistent with the pureTLS requirements.

Throws:
IOException

readObject

public static byte[] readObject(BufferedReader br,
                                String type)
                         throws IOException
Read an object

Throws:
IOException

writeBase64Object

public static void writeBase64Object(BufferedWriter bw,
                                     String type,
                                     String object)
                              throws IOException
Write an ovject that is already base64 encoded.

Throws:
IOException

writeObject

public static void writeObject(BufferedWriter out,
                               String type,
                               byte[] object)
                        throws IOException
Throws:
IOException

base64Encode

public static String base64Encode(byte[] in)
                           throws IOException
Convert a byte array into a BASE64 encoded String.

Parameters:
in - the bytes to be converted
Returns:
the BASE64 encoded String.
Throws:
IOException

base64Decode

public static byte[] base64Decode(Reader in)
                           throws IOException
Convert a BASE64 Encoded String into byte array.

Parameters:
the - BASE64 encoded String
Returns:
the decoded bytes.
Throws:
IOException

JXTA J2SE