public BigInteger[] decode(byte[] encoding) throws IOException { ASN1Sequence s = (ASN1Sequence) ASN1Primitive.fromByteArray(encoding); BigInteger[] sig = new BigInteger[2]; sig[0] = ASN1Integer.getInstance(s.getObjectAt(0)).getValue(); sig[1] = ASN1Integer.getInstance(s.getObjectAt(1)).getValue(); return sig; }
public static PrivateKeyInfo getInstance(Object obj) { if (obj instanceof PrivateKeyInfo) { return (PrivateKeyInfo) obj; } else if (obj != null) { return new PrivateKeyInfo(ASN1Sequence.getInstance(obj)); } return null; }
/** * Return a RecipientEncryptedKey object from the given object. * * <p>Accepted inputs: * * <ul> * <li>null → null * <li>{@link RecipientEncryptedKey} object * <li>{@link org.ripple.bouncycastle.asn1.ASN1Sequence#getInstance(java.lang.Object) * ASN1Sequence} input formats with RecipientEncryptedKey structure inside * </ul> * * @param obj the object we want converted. * @exception IllegalArgumentException if the object cannot be converted. */ public static RecipientEncryptedKey getInstance(Object obj) { if (obj instanceof RecipientEncryptedKey) { return (RecipientEncryptedKey) obj; } if (obj != null) { return new RecipientEncryptedKey(ASN1Sequence.getInstance(obj)); } return null; }
public List getExtendedKeyUsage() throws CertificateParsingException { byte[] bytes = this.getExtensionBytes("2.5.29.37"); if (bytes != null) { try { ASN1InputStream dIn = new ASN1InputStream(bytes); ASN1Sequence seq = (ASN1Sequence) dIn.readObject(); List list = new ArrayList(); for (int i = 0; i != seq.size(); i++) { list.add(((ASN1ObjectIdentifier) seq.getObjectAt(i)).getId()); } return Collections.unmodifiableList(list); } catch (Exception e) { throw new CertificateParsingException("error processing extended key usage extension"); } } return null; }
private static Collection getAlternativeNames(byte[] extVal) throws CertificateParsingException { if (extVal == null) { return null; } try { Collection temp = new ArrayList(); Enumeration it = ASN1Sequence.getInstance(extVal).getObjects(); while (it.hasMoreElements()) { GeneralName genName = GeneralName.getInstance(it.nextElement()); List list = new ArrayList(); list.add(Integers.valueOf(genName.getTagNo())); switch (genName.getTagNo()) { case GeneralName.ediPartyName: case GeneralName.x400Address: case GeneralName.otherName: list.add(genName.getEncoded()); break; case GeneralName.directoryName: list.add(X500Name.getInstance(RFC4519Style.INSTANCE, genName.getName()).toString()); break; case GeneralName.dNSName: case GeneralName.rfc822Name: case GeneralName.uniformResourceIdentifier: list.add(((ASN1String) genName.getName()).getString()); break; case GeneralName.registeredID: list.add(ASN1ObjectIdentifier.getInstance(genName.getName()).getId()); break; case GeneralName.iPAddress: byte[] addrBytes = DEROctetString.getInstance(genName.getName()).getOctets(); final String addr; try { addr = InetAddress.getByAddress(addrBytes).getHostAddress(); } catch (UnknownHostException e) { continue; } list.add(addr); break; default: throw new IOException("Bad tag number: " + genName.getTagNo()); } temp.add(Collections.unmodifiableList(list)); } if (temp.size() == 0) { return null; } return Collections.unmodifiableCollection(temp); } catch (Exception e) { throw new CertificateParsingException(e.getMessage()); } }
public static BasicConstraints getInstance(Object obj) { if (obj instanceof BasicConstraints) { return (BasicConstraints) obj; } if (obj instanceof X509Extension) { return getInstance(X509Extension.convertValueToObject((X509Extension) obj)); } if (obj != null) { return new BasicConstraints(ASN1Sequence.getInstance(obj)); } return null; }
/** * @deprecated use PrivateKeyInfo.getInstance() * @param seq */ public PrivateKeyInfo(ASN1Sequence seq) { Enumeration e = seq.getObjects(); BigInteger version = ((ASN1Integer) e.nextElement()).getValue(); if (version.intValue() != 0) { throw new IllegalArgumentException("wrong version for private key info"); } algId = AlgorithmIdentifier.getInstance(e.nextElement()); privKey = ASN1OctetString.getInstance(e.nextElement()); if (e.hasMoreElements()) { attributes = ASN1Set.getInstance((ASN1TaggedObject) e.nextElement(), false); } }
private Certificate readDERCertificate(InputStream in) throws IOException, CertificateParsingException { ASN1InputStream dIn = new ASN1InputStream(in); ASN1Sequence seq = (ASN1Sequence) dIn.readObject(); if (seq.size() > 1 && seq.getObjectAt(0) instanceof DERObjectIdentifier) { if (seq.getObjectAt(0).equals(PKCSObjectIdentifiers.signedData)) { sData = new SignedData(ASN1Sequence.getInstance((ASN1TaggedObject) seq.getObjectAt(1), true)) .getCertificates(); return getCertificate(); } } return new X509CertificateObject( org.ripple.bouncycastle.asn1.x509.Certificate.getInstance(seq)); }
private BasicConstraints(ASN1Sequence seq) { if (seq.size() == 0) { this.cA = null; this.pathLenConstraint = null; } else { if (seq.getObjectAt(0) instanceof ASN1Boolean) { this.cA = ASN1Boolean.getInstance(seq.getObjectAt(0)); } else { this.cA = null; this.pathLenConstraint = ASN1Integer.getInstance(seq.getObjectAt(0)); } if (seq.size() > 1) { if (this.cA != null) { this.pathLenConstraint = ASN1Integer.getInstance(seq.getObjectAt(1)); } else { throw new IllegalArgumentException("wrong sequence in constructor"); } } } }
/** * Return an RecipientEncryptedKey object from a tagged object. * * @param obj the tagged object holding the object we want. * @param explicit true if the object is meant to be explicitly tagged false otherwise. * @exception IllegalArgumentException if the object held by the tagged object cannot be * converted. */ public static RecipientEncryptedKey getInstance(ASN1TaggedObject obj, boolean explicit) { return getInstance(ASN1Sequence.getInstance(obj, explicit)); }
private RecipientEncryptedKey(ASN1Sequence seq) { identifier = KeyAgreeRecipientIdentifier.getInstance(seq.getObjectAt(0)); encryptedKey = (ASN1OctetString) seq.getObjectAt(1); }
public static PrivateKeyInfo getInstance(ASN1TaggedObject obj, boolean explicit) { return getInstance(ASN1Sequence.getInstance(obj, explicit)); }
public static BasicConstraints getInstance(ASN1TaggedObject obj, boolean explicit) { return getInstance(ASN1Sequence.getInstance(obj, explicit)); }