Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.bouncycastle.jcajce.util;
  
  
General JCA/JCE utility methods.
 
 public class JcaJceUtils
 {
     private JcaJceUtils()
     {
 
     }

    
Extract an ASN.1 encodable from an AlgorithmParameters object.

Parameters:
params the object to get the encoding used to create the return value.
Returns:
an ASN.1 object representing the primitives making up the params parameter.
Throws:
java.io.IOException if an encoding cannot be extracted.
 
     public static ASN1Encodable extractParameters(AlgorithmParameters params)
         throws IOException
     {
         // we try ASN.1 explicitly first just in case and then role back to the default.
         ASN1Encodable asn1Params;
         try
         {
             asn1Params = ASN1Primitive.fromByteArray(params.getEncoded("ASN.1"));
         }
         catch (Exception ex)
         {
             asn1Params = ASN1Primitive.fromByteArray(params.getEncoded());
         }
 
         return asn1Params;
     }

    
Load an AlgorithmParameters object with the passed in ASN.1 encodable - if possible.

Parameters:
params the AlgorithmParameters object to be initialised.
sParams the ASN.1 encodable to initialise params with.
Throws:
java.io.IOException if the parameters cannot be initialised.
 
     public static void loadParameters(AlgorithmParameters paramsASN1Encodable sParams)
         throws IOException
     {
         // we try ASN.1 explicitly first just in case and then role back to the default.
         try
         {
             params.init(sParams.toASN1Primitive().getEncoded(), "ASN.1");
         }
         catch (Exception ex)
         {
             params.init(sParams.toASN1Primitive().getEncoded());
         }
     }

    
Attempt to find a standard JCA name for the digest represented by the past in OID.

Parameters:
digestAlgOID the OID of the digest algorithm of interest.
Returns:
a string representing the standard name - the OID as a string if none available.
 
     public static String getDigestAlgName(
         ASN1ObjectIdentifier digestAlgOID)
     {
         if (..equals(digestAlgOID))
         {
             return "MD5";
         }
         else if (..equals(digestAlgOID))
         {
             return "SHA1";
         }
         else if (..equals(digestAlgOID))
         {
             return "SHA224";
         }
         else if (..equals(digestAlgOID))
         {
             return "SHA256";
         }
         else if (..equals(digestAlgOID))
         {
             return "SHA384";
         }
         else if (..equals(digestAlgOID))
        {
            return "SHA512";
        }
        else if (..equals(digestAlgOID))
        {
            return "RIPEMD128";
        }
        else if (..equals(digestAlgOID))
        {
            return "RIPEMD160";
        }
        else if (..equals(digestAlgOID))
        {
            return "RIPEMD256";
        }
        else if (..equals(digestAlgOID))
        {
            return "GOST3411";
        }
        else
        {
            return digestAlgOID.getId();
        }
    }
New to GrepCode? Check out our FAQ X