Take the 2-minute tour ×

I haven't seen any examples on the internet for this so as far as I know this is the first time someone is trying this in Java which I find hard to believe.

I'm just trying to work with the .pem, .p12 and .cer files I've been given to generate a signature file for my manifest.json. Here is what I have, which gives me an InvalidKeyException version mismatch: (supported: 00, parsed: 03

See the comment in the code below where the error is happening. I've viewed a few examples in another languages of how people are doing this with openssl but there must be a Java equivalent??

    File pemFile = new File("AWWdevCert.pem");
    File passCer = new File("pass.cer");
    File passP12 = new File("pass.p12"); 

    KeyFactory keyFactory = KeyFactory.getInstance("RSA");
    KeySpec ks = new PKCS8EncodedKeySpec(FileUtils.readFileToByteArray(passP12));
    PrivateKey privKey = keyFactory.generatePrivate(ks); // ERROR HERE

    CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
    InputStream in = new ByteArrayInputStream(FileUtils.readFileToByteArray(passCer));
    X509Certificate passCert = (X509Certificate)certFactory.generateCertificate(in); //don't know what to do with this

    File inputFile = new File("WebContent/WEB-INF/Lowes.raw/manifest.json"); 
    FileInputStream freader = null;
    int sizecontent = ((int) inputFile.length());
    byte[] contentbytes = new byte[sizecontent];
    freader = new FileInputStream(inputFile);
    System.out.println("\nContent Bytes: " + freader.read(contentbytes, 0, sizecontent));

    Signature signature = Signature.getInstance("Sha1WithRSA");

    byte[] signedData = signature.sign();

    //create signature file
    File signatureFile = new File(passDirectory.getAbsolutePath()+File.separator+"signature");
share|improve this question

1 Answer 1

up vote 4 down vote accepted

Check this jpasskit project on github

share|improve this answer
Thanks! Guess I should have Googled for something more along the lines of "java passkit". –  Justin Oct 10 '12 at 17:42
I am using it with Spring framework, though jpasskit's standlone server implementation is not very useful for me, the abstraction and encapsulation of Pass object system is very easy to use. –  Jerry Tian Oct 22 '12 at 7:21
@JerryTian would you mind sharing some info about integrating jpasskit with Spring? I'm trying to use it with Grails and although stand-alone it creates passes nicely, when called from Grails I get java.lang.NoSuchFieldError - data, which leaves me with no clue about what happened :/ –  Krystian Oct 25 '12 at 23:00
@Krystian Although I am not familiar with Grails, I suggest you open another question on this, like "Srping framework and Grails integration with jpasskit failure", and put your full stackstrace there. –  Jerry Tian Oct 26 '12 at 3:13

Your Answer


