Java Code Examples for org.bouncycastle.asn1.ASN1ObjectIdentifier#toString()

The following examples show how to use org.bouncycastle.asn1.ASN1ObjectIdentifier#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PublicKey.java    From hedera-sdk-java with Apache License 2.0 5 votes vote down vote up
public static PublicKey fromString(String keyString) {
    SubjectPublicKeyInfo pubKeyInfo;

    try {
        byte[] keyBytes = Hex.decode(keyString);

        // it could be a hex-encoded raw public key or a DER-encoded public key
        if (keyBytes.length == Ed25519.PUBLIC_KEY_SIZE) {
            return Ed25519PublicKey.fromBytes(keyBytes);
        }

        pubKeyInfo = SubjectPublicKeyInfo.getInstance(keyBytes);
    } catch (Exception e) {
        throw new IllegalArgumentException("Failed to parse public key", e);
    }

    ASN1ObjectIdentifier algId = pubKeyInfo.getAlgorithm()
        .getAlgorithm();

    if (algId.equals(EdECObjectIdentifiers.id_Ed25519)) {
        return Ed25519PublicKey.fromBytes(
            pubKeyInfo.getPublicKeyData()
                .getBytes());
    } else {
        throw new IllegalArgumentException("Unsupported public key type: " + algId.toString());
    }
}
 
Example 2
Source File: CAdESAttribute.java    From dss with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public String toString() {
	ASN1ObjectIdentifier asn1Oid = getASN1Oid();
	if (asn1Oid != null) {
		return asn1Oid.toString();
	}
	return Utils.EMPTY_STRING;
}
 
Example 3
Source File: GPData.java    From GlobalPlatformPro with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static String oid2string(byte[] oid) {
    try {
        // Prepend 0x06 tag, if not present
        // XXX: if ber-tlv allows to fetch constructed data, this is not needed
        if (oid[0] != 0x06) {
            oid = GPUtils.concatenate(new byte[]{0x06, (byte) oid.length}, oid);
        }
        ASN1ObjectIdentifier realoid = (ASN1ObjectIdentifier) ASN1ObjectIdentifier.fromByteArray(oid);
        if (realoid == null)
            throw new IllegalArgumentException("Could not parse OID from " + HexUtils.bin2hex(oid));
        return realoid.toString();
    } catch (IOException e) {
        throw new IllegalArgumentException("Could not handle " + HexUtils.bin2hex(oid));
    }
}