我正在开发一个创建 PKI 以在 Android 中获取证书请求的项目。
现在我正在使用 Spongycastle,它在 Android 5 及更高版本中运行,但在 4.X 上它向我展示了这个:
Signature SHA256WITHECDSA implementation not found
java.security.NoSuchAlgorithmException: Signature SHA256WITHECDSA implementation not found
at org.apache.harmony.security.fortress.Engine.notFound(Engine.java:177)
at org.apache.harmony.security.fortress.Engine.getInstance(Engine.java:170)
at java.security.Signature.getSignatureInstance(Signature.java:178)
at java.security.Signature.getInstance(Signature.java:146)
at org.spongycastle.jce.PKCS10CertificationRequest.<init>(PKCS10CertificationRequest.java:363)
at org.spongycastle.jce.PKCS10CertificationRequest.<init>(PKCS10CertificationRequest.java:248)
at com.unipagos.app.enrollmentprocess.EnrollmentStep5FragmentActivity.createPKI(EnrollmentStep5FragmentActivity.java:199)
at com.unipagos.app.enrollmentprocess.EnrollmentStep5FragmentActivity.onPostCreate(EnrollmentStep5FragmentActivity.java:145)
at android.app.Instrumentation.callActivityOnPostCreate(Instrumentation.java:1157)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2075)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2117)
at android.app.ActivityThread.access$700(ActivityThread.java:134)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1218)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4867)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
at dalvik.system.NativeStart.main(Native Method)
创建证书请求的代码是这样的:
public String createPKI(String mdnString) {
try {
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("EC");
//KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("ECDSA", "SC");
ECGenParameterSpec ecGenSpec = new ECGenParameterSpec("prime256v1");
keyPairGenerator.initialize(ecGenSpec, new SecureRandom());
KeyPair kp = keyPairGenerator.generateKeyPair();
publicKey = kp.getPublic();
privateKey = kp.getPrivate();
PKCS10CertificationRequest kpGen = new PKCS10CertificationRequest("SHA256WITHECDSA", new X509Name(String.format("UID=%s", mdnString)), publicKey, null, privateKey);
String certRequest = Base64.encodeToString(kpGen.getEncoded(), Base64.DEFAULT);
certRequest = certRequest.replace("\n", "");
return certRequest;
} catch(Exception e) {
if (Constants.DEBUG) {
Log.v("Exception", e.getMessage());
}
e.printStackTrace();
return null;
}
}
我正在使用的 spongycastle 版本是:sc-light-jdk15on-1.47.0.2.jar 和 scprov-jdk15on-1.47.0.2.jar
¿ 对此有什么想法吗?