Example usage for org.bouncycastle.asn1 DERIA5String toString

List of usage examples for org.bouncycastle.asn1 DERIA5String toString

Introduction

In this page you can find the example usage for org.bouncycastle.asn1 DERIA5String toString.

Prototype

public String toString() 

Source Link

Usage

From source file:net.sf.keystore_explorer.crypto.x509.X509Ext.java

License:Open Source License

private String getBiometricInfoStringValue(byte[] octets) {

    // @formatter:off

    /*//w ww .j  a v a  2 s  .c  o  m
       BiometricSyntax ::= SEQUENCE OF BiometricData
       BiometricData ::= SEQUENCE
       {
    typeOfBiometricData TypeOfBiometricData,
    hashAlgorithm AlgorithmIdentifier,
    biometricDataHash OCTET STRING,
    sourceDataUri IA5String OPTIONAL
       }
       TypeOfBiometricData ::= CHOICE
       {
    predefinedBiometricType PredefinedBiometricType,
    biometricDataId OBJECT IDENTIIFER
       }
       PredefinedBiometricType ::= INTEGER
       {
    picture(0),
    handwritten-signature(1)
       }
     */

    // @formatter:on

    StringBuilder sb = new StringBuilder();
    int biometricDataNr = 0;

    ASN1Sequence asn1Sequence = ASN1Sequence.getInstance(octets);

    for (ASN1Encodable asn1Encodable : asn1Sequence.toArray()) {
        BiometricData biometricData = BiometricData.getInstance(asn1Encodable);
        TypeOfBiometricData typeOfBiometricData = biometricData.getTypeOfBiometricData();
        AlgorithmIdentifier hashAlgorithm = biometricData.getHashAlgorithm();
        ASN1OctetString biometricDataHash = biometricData.getBiometricDataHash();
        DERIA5String sourceDataUri = biometricData.getSourceDataUri();

        sb.append(MessageFormat.format(res.getString("BiometricInfo.BiometricData"), biometricDataNr));
        sb.append(NEWLINE);

        sb.append(INDENT);
        if (typeOfBiometricData.isPredefined()) {
            int type = typeOfBiometricData.getPredefinedBiometricType();
            sb.append(MessageFormat.format(res.getString("BiometricInfo.TypeOfBiometricData"), type));
        } else {
            String biometricDataOid = typeOfBiometricData.getBiometricDataOid().getId();
            sb.append(
                    MessageFormat.format(res.getString("BiometricInfo.TypeOfBiometricData"), biometricDataOid));
        }
        sb.append(NEWLINE);

        sb.append(INDENT);
        sb.append(MessageFormat.format(res.getString("BiometricInfo.HashAlgorithm"),
                hashAlgorithm.getAlgorithm().getId()));
        sb.append(NEWLINE);

        sb.append(INDENT);
        sb.append(MessageFormat.format(res.getString("BiometricInfo.BiometricDataHash"),
                HexUtil.getHexString(biometricDataHash.getOctets())));
        sb.append(NEWLINE);

        if (sourceDataUri != null) { // optional
            sb.append(INDENT);
            sb.append(MessageFormat.format(res.getString("BiometricInfo.SourceDataUri"),
                    sourceDataUri.toString()));
            sb.append(NEWLINE);
        }
    }

    return sb.toString();
}