PKCS1Util { public static RSAPrivateCrtKeySpec decodePKCS1(byte[] keyBytes) throws IOException { DerParser parser = new DerParser(keyBytes); Asn1Object sequence = parser.read(); sequence.validateSequence(); parser = new DerParser(sequence.getValue()); parser.read(); return new RSAPrivateCrtKeySpec(next(parser), next(parser), next(parser), next(parser), next(parser), next(parser), next(parser), next(parser)); } private  PKCS1Util(); static RSAPrivateCrtKeySpec decodePKCS1(byte[] keyBytes);  }
@Test public void simple() throws IOException, NoSuchAlgorithmException, InvalidKeySpecException { RSAPrivateCrtKeySpec spec = PKCS1Util.decodePKCS1(Base64Util.decode(PRIVATE_KEY)); assertNotNull(spec); assertEquals(new BigInteger("65537"),spec.getPublicExponent()); assertEquals(new BigInteger("17219073728753538877351436880713775379656064037529658955194218882887990854659277" + "14926866974743136717398950769494187526607437089900175320890853259761202632924910" + "04313716240382424077365899979237567821238335068353270396753262938612364085446101" + "06439976729028133029376341040827650031161824951684561808300496926367402762121624" + "84716729598919532254889795000011013630896579601633649087197314473243762156761264" + "28213494680134367573578684374434499094707511493610021020953064686646715594465961" + "57768682849057097693703094001987209424161987563379538988444327461934240605326845" + "582692396320855699767767177230708015442200422586240491997"), spec.getPrivateExponent()); }