/** * Implementation of the {@code engineInit} method. * * @param params the encoded parameter specification * @throws IOException if decoding failed */ protected final void engineInit(final byte[] params) throws IOException { final DERDecoder decoder = new DERDecoder(params); try { parameterSpec = engineDecode(decoder); encoded = params; } catch (ASN1Exception e) { throw log.failedToDecode(e); } }
/** * Get the key identifier, which is composed of the 160-bit SHA-1 hash of the value of the BIT STRING * {@code subjectPublicKey} (excluding the tag, length, and number of unused bits), as per * <a href="https://tools.ietf.org/html/rfc3280">RFC 3280</a>. * * @param publicKey the public key * @return the key identifier */ public static byte[] getKeyIdentifier(final PublicKey publicKey) { DERDecoder decoder = new DERDecoder(publicKey.getEncoded()); decoder.startSequence(); decoder.skipElement(); // skip the algorithm byte[] subjectPublicKey = decoder.decodeBitString(); decoder.endSequence(); final MessageDigest messageDigest; try { messageDigest = MessageDigest.getInstance("SHA-1"); messageDigest.update(subjectPublicKey); return messageDigest.digest(); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException(e); } } }
@Override public BigInteger decodeBitStringAsInteger() { DERDecoder decoder = new DERDecoder(decodeBitString()); if (decoder.peekType() != INTEGER_TYPE) { throw log.asnUnexpectedTag(); } return decoder.decodeInteger(); }
if (privateKey instanceof ECPrivateKey) { DERDecoder derDecoder = new DERDecoder(signatureBytes); derDecoder.startSequence(); byte[] r = derDecoder.drainElementValue();
private static PublicKey parsePemPublicKey(String type, ByteIterator byteIterator) throws IllegalArgumentException { if (! type.equals(PUBLIC_KEY_FORMAT)) { throw log.invalidPemType(PUBLIC_KEY_FORMAT, type); } try { byte[] der = byteIterator.drain(); DERDecoder derDecoder = new DERDecoder(der); derDecoder.startSequence(); switch (derDecoder.peekType()) { case ASN1.SEQUENCE_TYPE: derDecoder.startSequence(); String algorithm = derDecoder.decodeObjectIdentifierAsKeyAlgorithm(); if (algorithm != null) { return KeyFactory.getInstance(algorithm).generatePublic(new X509EncodedKeySpec(der)); } throw log.asnUnrecognisedAlgorithm(algorithm); default: throw log.asnUnexpectedTag(); } } catch (Exception cause) { throw log.publicKeyParseError(cause); } }
private static PrivateKey parsePemPrivateKey(String type, ByteIterator byteIterator) throws IllegalArgumentException { if (! type.equals(PRIVATE_KEY_FORMAT)) { throw log.invalidPemType(PRIVATE_KEY_FORMAT, type); } try { byte[] der = byteIterator.drain(); DERDecoder derDecoder = new DERDecoder(der); derDecoder.startSequence(); // Version if (derDecoder.peekType() != ASN1.INTEGER_TYPE) throw log.asnUnexpectedTag(); derDecoder.skipElement(); // AlgorithmIdentifier derDecoder.startSequence(); String algorithm = derDecoder.decodeObjectIdentifierAsKeyAlgorithm(); if (algorithm != null) { return KeyFactory.getInstance(algorithm).generatePrivate(new PKCS8EncodedKeySpec(der)); } throw log.asnUnrecognisedAlgorithm(algorithm); } catch (Exception cause) { throw log.privateKeyParseError(cause); } }
/** * <p> * Create an {@code OtherName} that is defined as: * * <pre> * OtherName ::= SEQUENCE { * type-id OBJECT IDENTIFIER, * value [0] EXPLICIT ANY DEFINED BY type-id } * </pre> * </p> * * @param encodedName the DER encoded form of the name, as a byte array * @throws ASN1Exception if {@code encodedName} is not DER encoded */ public OtherName(final byte[] encodedName) throws ASN1Exception { super(OTHER_NAME); this.encodedName = encodedName; final DERDecoder decoder = new DERDecoder(encodedName); decoder.startSequence(); typeId = decoder.decodeObjectIdentifier(); encodedValue = decoder.drainElement(); decoder.endSequence(); }
Assert.checkNotNullParam("oids", oids); final Set<String> requiredAttributes = new HashSet<>(Arrays.asList(oids)); final ASN1Decoder decoder = new DERDecoder(principal.getEncoded()); decoder.startSequence(); while (decoder.hasNextElement() && ! requiredAttributes.isEmpty()) {
final ASN1Decoder decoder = new DERDecoder(principal.getEncoded()); String[] strings = NO_STRINGS; int len = 0;
assert matchedAlgorithm != null; // because KeyPairCredential is an AlgorithmCredential final DERDecoder decoder = new DERDecoder(encoded); decoder.startSequence(); final byte[] publicBytes = decoder.drainElement(); final String matchedAlgorithm = bottomEntry.getAlgorithm(); assert matchedAlgorithm != null; // because it is an AlgorithmCredential final DERDecoder decoder = new DERDecoder(encoded); final CertificateFactory certificateFactory = CertificateFactory.getInstance(X_509); final int count = decoder.decodeInteger().intValueExact(); final String matchedAlgorithm = bottomEntry.getAlgorithm(); assert matchedAlgorithm != null; // because it is an AlgorithmCredential final DERDecoder decoder = new DERDecoder(encoded);
final DERDecoder decoder = new DERDecoder(token); decoder.decodeImplicit(APPLICATION_SPECIFIC_MASK, 0); decoder.startSequence();
switch (state) { case ST_CHALLENGE_RESPONSE: { final DERDecoder decoder = new DERDecoder(challenge); List<TrustedAuthority> trustedAuthorities = null; List<GeneralName> entityB = null; final DERDecoder decoder = new DERDecoder(challenge); List<GeneralName> entityA = null; try {
final DERDecoder decoder = new DERDecoder(response); byte[] randomA; X509Certificate clientCert;
/** * Implementation of the {@code engineInit} method. * * @param params the encoded parameter specification * @throws IOException if decoding failed */ protected final void engineInit(final byte[] params) throws IOException { final DERDecoder decoder = new DERDecoder(params); try { parameterSpec = engineDecode(decoder); encoded = params; } catch (ASN1Exception e) { throw log.failedToDecode(e); } }
/** * Implementation of the {@code engineInit} method. * * @param params the encoded parameter specification * @throws IOException if decoding failed */ protected final void engineInit(final byte[] params) throws IOException { final DERDecoder decoder = new DERDecoder(params); try { parameterSpec = engineDecode(decoder); encoded = params; } catch (ASN1Exception e) { throw log.failedToDecode(e); } }
/** * Implementation of the {@code engineInit} method. * * @param params the encoded parameter specification * @throws IOException if decoding failed */ protected final void engineInit(final byte[] params) throws IOException { final DERDecoder decoder = new DERDecoder(params); try { parameterSpec = engineDecode(decoder); encoded = params; } catch (ASN1Exception e) { throw log.failedToDecode(e); } }
@Override public BigInteger decodeBitStringAsInteger() { DERDecoder decoder = new DERDecoder(decodeBitString()); if (decoder.peekType() != INTEGER_TYPE) { throw log.asnUnexpectedTag(); } return decoder.decodeInteger(); }
@Override public BigInteger decodeBitStringAsInteger() { DERDecoder decoder = new DERDecoder(decodeBitString()); if (decoder.peekType() != INTEGER_TYPE) { throw log.asnUnexpectedTag(); } return decoder.decodeInteger(); }
@Override public BigInteger decodeBitStringAsInteger() { DERDecoder decoder = new DERDecoder(decodeBitString()); if (decoder.peekType() != INTEGER_TYPE) { throw log.asnUnexpectedTag(); } return decoder.decodeInteger(); }
private static PublicKey parsePemPublicKey(String type, ByteIterator byteIterator) throws IllegalArgumentException { if (! type.equals(PUBLIC_KEY_FORMAT)) { throw log.invalidPemType(PUBLIC_KEY_FORMAT, type); } try { byte[] der = byteIterator.drain(); DERDecoder derDecoder = new DERDecoder(der); derDecoder.startSequence(); switch (derDecoder.peekType()) { case ASN1.SEQUENCE_TYPE: derDecoder.startSequence(); String algorithm = derDecoder.decodeObjectIdentifierAsKeyAlgorithm(); if (algorithm != null) { return KeyFactory.getInstance(algorithm).generatePublic(new X509EncodedKeySpec(der)); } throw log.asnUnrecognisedAlgorithm(algorithm); default: throw log.asnUnexpectedTag(); } } catch (Exception cause) { throw log.publicKeyParseError(cause); } }