openssl genrsa -3 -out testkey.pem 2048
openssl req -new -x509 -key testkey.pem -out testkey.x509.pem -days 10000
openssl pkcs8 -in testkey.pem -topk8 -outform DER -out testkey.pk8 -nocrypt
成功生成:testkey.pk8
signapk.jar testkey.x509.pem testkey.pk8 HelloJni_test.apk HelloJni_test_signed.apk
import sun.security.pkcs.PKCS7; import java.io.FileInputStream; import java.io.IOException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; public class Test { public static void main(String[] args) throws CertificateException, IOException { if(args.length < 1){ System.out.println("Error arguments"); System.exit(-1); } FileInputStream fis = new FileInputStream(args[0]); PKCS7 pkcs7 = new PKCS7(fis); X509Certificate publicKey = pkcs7.getCertificates()[0]; System.out.println("issuer1:" + publicKey.getIssuerDN()); System.out.println("subject2:" + publicKey.getSubjectDN()); System.out.println(publicKey.getPublicKey()); } }
issuer1:[email protected], CN=netease, OU=sing, O=sing, L=hangzhou, ST=zhejiang, C=cn subject2:[email protected], CN=netease, OU=sing, O=sing, L=hangzhou, ST=zhejiang, C=cn Sun RSA public key, 2048 bits modulus: 22676173355286459097573334286481325549679742508291213299264044486977814024339605340628711274677072768829606315047576874911034554527084043177679494350712443522287175454777833436168772665418404933643096476891010605269397100182350607109602567424649311950932263840379746712271144600813750815453035262110486680532806609381313030573833526182249935950105614529180848998274172532233764292631298041869124308804566439799309159573665297279480681980653336799995434022140192702337503587221467398087020249337183520598982287860366619939017957775007220964826029614540987113512464831360539897307371766206991936881303261221737921332207 public exponent: 3