Class EntityUtil

    • Field Detail

      • randomCharDictionary

        private static final byte[] randomCharDictionary
    • Constructor Detail

      • EntityUtil

        EntityUtil()
    • Method Detail

      • encodeX509CertificateChain

        public static void encodeX509CertificateChain​(DEREncoder encoder,
                                                      X509Certificate[] certChain)
                                               throws ASN1Exception
        Encode an ASN.1 set of certificates using the given DER encoder and the given X509Certificate chain.
        Parameters:
        encoder - the DER encoder
        certChain - the X.509 certificate chain to encode
        Throws:
        ASN1Exception - if an error occurs while encoding the given certificate chain
      • encodeAlgorithmIdentifier

        public static void encodeAlgorithmIdentifier​(DEREncoder encoder,
                                                     String objectIdentifier,
                                                     boolean omitParametersField)
                                              throws ASN1Exception

        Encode an AlgorithmIdentifier without any parameters using the given DER encoder and object identifier, where AlgorithmIdentifier is defined as:

              AlgorithmIdentifier  ::=  SEQUENCE  {
                  algorithm      OBJECT IDENTIFIER,
                  parameters     ANY DEFINED BY algorithm OPTIONAL
              }
         

        Parameters:
        encoder - the DER encoder
        objectIdentifier - the object identifier for the algorithm
        omitParametersField - true if the parameters field should be ommitted in the encoding and false otherwise
        Throws:
        ASN1Exception - if the given object identifier is invalid
      • encodeAlgorithmIdentifier

        public static void encodeAlgorithmIdentifier​(DEREncoder encoder,
                                                     String algorithm)
                                              throws ASN1Exception

        Encode an AlgorithmIdentifier using the given DER encoder, where AlgorithmIdentifier is defined as:

              AlgorithmIdentifier  ::=  SEQUENCE  {
                  algorithm      OBJECT IDENTIFIER,
                  parameters     ANY DEFINED BY algorithm OPTIONAL
              }
         

        Parameters:
        encoder - the DER encoder
        algorithm - the algorithm name
        Throws:
        ASN1Exception - if the given algorithm name is unrecognised
      • encodeGeneralNames

        public static void encodeGeneralNames​(DEREncoder encoder,
                                              List<GeneralName> generalNames)
                                       throws ASN1Exception

        Encode a GeneralNames element using the given DER encoder, where GeneralNames is defined as:

              GeneralNames ::= SEQUENCE SIZE (1..MAX) OF GeneralName
         

        Parameters:
        encoder - the DER encoder
        generalNames - the general names, as a List where each entry is a GeneralName
        Throws:
        ASN1Exception - if any of the general names are invalid
      • encodeGeneralNames

        public static void encodeGeneralNames​(DEREncoder encoder,
                                              GeneralName generalName)
                                       throws ASN1Exception
        Encode a GeneralNames element consisting of one general name using the given DER encoder.
        Parameters:
        encoder - the DER encoder
        generalName - the general name
        Throws:
        ASN1Exception - if the general name is invalid
      • encodeRandomNumber

        public static byte[] encodeRandomNumber​(DEREncoder encoder,
                                                SecureRandom secureRandom)

        Encode a RandomNumber element using the given DER encoder, where RandomNumber is defined as:

              RandomNumber ::= OCTET STRING (SIZE(8..MAX))
         

        Parameters:
        encoder - the DER encoder
        secureRandom - the secure random to use (may be null)
      • generateRandomString

        public static byte[] generateRandomString​(int length,
                                                  Random random)
      • decodeGeneralNames

        public static List<GeneralName> decodeGeneralNames​(DERDecoder decoder)
                                                    throws ASN1Exception
        Decode the next element from the given DER decoder as a GeneralNames element.
        Parameters:
        decoder - the DER decoder
        Returns:
        the general names
        Throws:
        ASN1Exception - if the next element from the given decoder is not a general names element
      • decodeX509CertificateChain

        public static X509Certificate[] decodeX509CertificateChain​(DERDecoder decoder)
                                                            throws ASN1Exception
        Decode the next element from the given DER decoder as an X.509 certificate chain.
        Parameters:
        decoder - the DER decoder
        Returns:
        the X.509 certificate chain
        Throws:
        ASN1Exception - if the next element from the given decoder is not an X.509 certificate chain or if an error occurs while decoding the X.509 certificate chain
      • decodeCertificateData

        public static X509Certificate[] decodeCertificateData​(DERDecoder decoder)
                                                       throws ASN1Exception

        Decode the next element from the given DER decoder as a CertData element, which is defined as follows:

              CertData ::= CHOICE {
                  certificateSet     SET SIZE (1..MAX) OF Certificate,
                  certURL            IA5String (Note: No support for certificate URL)
              }
         

        Parameters:
        decoder - the DER decoder
        Returns:
        the X.509 certificate or certificate chain
        Throws:
        ASN1Exception - if the next element from the given decoder is not a CertData element or if an error occurs while decoding the certificate data
      • decodeTrustedAuthorities

        public static List<TrustedAuthority> decodeTrustedAuthorities​(DERDecoder decoder)
                                                               throws ASN1Exception
        Decode the next element from the given DER decoder as a trusted authorities element.
        Parameters:
        decoder - the DER decoder
        Returns:
        the trusted authorities
        Throws:
        ASN1Exception - if the next element from the given decoder is not a trusted authorities element or if an error occurs while decoding the trusted authorities element
      • matchGeneralName

        public static boolean matchGeneralName​(GeneralName generalName,
                                               GeneralName actualGeneralName)
      • getDistinguishedNameFromGeneralNames

        public static String getDistinguishedNameFromGeneralNames​(List<GeneralName> generalNames)