org.netserv.ipauth.util
Class CryptoHelper

java.lang.Object
  extended by org.netserv.ipauth.util.CryptoHelper

public class CryptoHelper
extends java.lang.Object


Constructor Summary
CryptoHelper()
           
 
Method Summary
static byte[] createNonce(int len)
          Create Random Nonces
static org.bouncycastle.asn1.DERObjectIdentifier createSigId(org.bouncycastle.asn1.DERObjectIdentifier encId, org.bouncycastle.asn1.DERObjectIdentifier digestId)
          Combine encryption algorithm and digest algorithm
static java.lang.String[] getCommonNames(java.security.Principal name)
          Converting Common Names to Strings
static java.lang.String[] getCommonNames(org.bouncycastle.asn1.x509.X509Name name)
          Converting Common Names to Strings
static byte[] getGeneralName(org.bouncycastle.asn1.x509.GeneralName name)
          Converting General Names to Byte String
static void installBC()
          Installing Bouncy Castle Provider
static org.bouncycastle.asn1.x509.SubjectPublicKeyInfo PublicKeyToSubjectPublicKeyInfo(java.security.PublicKey publicKey)
          Convert java.security.PublicKey objects to org.bouncycastle.asn1.x509.SubjectPublicKeyInfo objects
static java.security.PublicKey SubjectPublicKeyInfoToPublicKey(org.bouncycastle.asn1.x509.SubjectPublicKeyInfo subjectPKInfo)
          Convert org.bouncycastle.asn1.x509.SubjectPublicKeyInfo objects to java.security.PublicKey objects
static java.security.cert.X509Certificate X509CertificateStructureToX509Certificate(org.bouncycastle.asn1.x509.X509CertificateStructure certstr)
          Convert org.bouncycastle.asn1.x509.X509CertificateStructure objects to java.security.cert.X509Certificate object.
static org.bouncycastle.asn1.x509.X509CertificateStructure X509CertificateToX509CertificateStructure(java.security.cert.X509Certificate cert)
          Convert java.security.cert.X509Certificate objects to org.bouncycastle.asn1.x509.X509CertificateStructure objects.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CryptoHelper

public CryptoHelper()
Method Detail

createNonce

public static byte[] createNonce(int len)
Create Random Nonces

Parameters:
len - Length of nonces
Returns:
Byte array

createSigId

public static org.bouncycastle.asn1.DERObjectIdentifier createSigId(org.bouncycastle.asn1.DERObjectIdentifier encId,
                                                                    org.bouncycastle.asn1.DERObjectIdentifier digestId)
Combine encryption algorithm and digest algorithm

Parameters:
encId - encryption id
digestId - digest id
Returns:
DERObjectIdentifer of the algorithm

getCommonNames

public static java.lang.String[] getCommonNames(java.security.Principal name)
Converting Common Names to Strings

Parameters:
name - Principal object
Returns:
Array of string represent the common names

getCommonNames

public static java.lang.String[] getCommonNames(org.bouncycastle.asn1.x509.X509Name name)
Converting Common Names to Strings

Parameters:
name - X509Name object
Returns:
Array of string represent the common names

getGeneralName

public static byte[] getGeneralName(org.bouncycastle.asn1.x509.GeneralName name)
                             throws java.io.IOException
Converting General Names to Byte String
 GeneralName ::= CHOICE {
   otherName             [0]   OtherName,
   rfc822Name            [1]   IA5String,
   dNSName               [2]   IA5String,
   x400Address           [3]   ORAddress,
   directoryName         [4]   Name,
   ediPartyName          [5]   EDIPartyName,
   uniformResourceIdentifier     [6]   IA5String,
   iPAddress             [7]   OCTET STRING,
   registeredID          [8]   OBJECT IDENTIFIER}

 OtherName ::= SEQUENCE {
   type-id  OBJECT IDENTIFIER,
   value    [0] EXPLICIT ANY DEFINED BY type-id }

 EDIPartyName ::= SEQUENCE {
   nameAssigner      [0]   DirectoryString OPTIONAL,
   partyName         [1]   DirectoryString }

 Name ::= CHOICE { RDNSequence }
 

Parameters:
name - General Name
Returns:
Byte String
Throws:
java.io.IOException

installBC

public static void installBC()
Installing Bouncy Castle Provider


PublicKeyToSubjectPublicKeyInfo

public static org.bouncycastle.asn1.x509.SubjectPublicKeyInfo PublicKeyToSubjectPublicKeyInfo(java.security.PublicKey publicKey)
                                                                                       throws java.security.InvalidKeyException
Convert java.security.PublicKey objects to org.bouncycastle.asn1.x509.SubjectPublicKeyInfo objects

Parameters:
publicKey - PublicKey object
Returns:
SubjectPublicKeyInfo object
Throws:
java.security.InvalidKeyException - if the object cannot be encoded
See Also:
SubjectPublicKeyInfoToPublicKey

SubjectPublicKeyInfoToPublicKey

public static java.security.PublicKey SubjectPublicKeyInfoToPublicKey(org.bouncycastle.asn1.x509.SubjectPublicKeyInfo subjectPKInfo)
                                                               throws java.security.KeyException
Convert org.bouncycastle.asn1.x509.SubjectPublicKeyInfo objects to java.security.PublicKey objects

Parameters:
subjectPKInfo - SubjectPublicKeyInfo object
Returns:
PublicKey object
Throws:
java.security.KeyException - if the object cannot be decoded
See Also:
PublicKeyToSubjectPublicKeyInfo

X509CertificateStructureToX509Certificate

public static java.security.cert.X509Certificate X509CertificateStructureToX509Certificate(org.bouncycastle.asn1.x509.X509CertificateStructure certstr)
                                                                                    throws java.security.cert.CertificateException
Convert org.bouncycastle.asn1.x509.X509CertificateStructure objects to java.security.cert.X509Certificate object.

Parameters:
certstr - X509Certificate object
Returns:
X509CertificateStructure object
Throws:
java.security.cert.CertificateException - if the object cannot be decoded

X509CertificateToX509CertificateStructure

public static org.bouncycastle.asn1.x509.X509CertificateStructure X509CertificateToX509CertificateStructure(java.security.cert.X509Certificate cert)
                                                                                                     throws java.security.cert.CertificateEncodingException
Convert java.security.cert.X509Certificate objects to org.bouncycastle.asn1.x509.X509CertificateStructure objects.

Parameters:
cert - X509Certificate object
Returns:
X509CertificateStructure object
Throws:
java.security.cert.CertificateEncodingException - if the object cannot be encoded