Generate passbook signature in Java
java, passbook, signature
Solution
Check this jpasskit project on github
Problem
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)); freader.close(); Signature signature = Signature.getInstance("Sha1WithRSA"); signature.initSign(privKey); signature.update(contentbytes); byte[] signedData = signature.sign(); //create signature file File signatureFile = new File(passDirectory.getAbsolutePath()+File.separator+"signature"); ```