DerValue[] seq = derReader.getSequence(0);
@Override public RSAPrivateKeySpec readPrivateKey(byte[] privateKeyDerBytes) throws IOException { sun.security.util.DerInputStream derStream = new sun.security.util.DerInputStream(privateKeyDerBytes); sun.security.util.DerValue[] derValues = derStream.getSequence(0); BigInteger modulus = derValues[1].getBigInteger(); BigInteger privateExponent = derValues[3].getBigInteger(); return new RSAPrivateKeySpec(modulus, privateExponent); }
/** * Fix for OAUTH-96, sort of. Some python clients send and invalid cert request * because the programmer does not set the version (to zero). Python then sends a * zero-length integer. Now, as this violates the PKCS10 spec., and should be rejected. * Bouncy Castle will ignore it but the Sun libraries will throw an extremely * unhelpful IOException. The method does the check and throws a much better exception. * * @param derEncoded */ protected void checkVersion(byte[] derEncoded) { try { DerInputStream derInputStream = new DerInputStream(derEncoded); DerValue[] seq = derInputStream.getSequence(3); //try and get the first three elements. seq[0].data.getBigInteger(); } catch (IOException iox) { throw new InvalidCertRequestException("Invalid Certification Request. Be sure that the version number " + "of the (PCKS10) request is set to zero.", iox); } }
DerValue[] seq = derReader.getSequence(0);
public static PrivateKey generatePrivateKeyWithPKCS1(byte[] privateKeyBytes) { try { DerInputStream derReader = new DerInputStream(privateKeyBytes); DerValue[] seq = derReader.getSequence(0); if (seq.length < 9) { System.out.println("Could not parse a PKCS1 private key.");
DerValue[] derval = din.getSequence(1); X509Certificate[] certchain = new X509CertImpl[derval.length];