来自 java 和 dart 的 x509 证书的编码公钥不同

问题描述 投票:0回答:0

我已经在 flutter 中使用 basic_utils 包从 x509 证书中获取公钥,但它不同于 java 编码的公钥。

Java代码

  public static byte[] getPublicKeyFromCert(String certificateValue) {
    byte[] CertData = Base64.decode(certificateValue, Base64.DEFAULT);
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(CertData);
    CertificateFactory certificatefactory = null;
    try {
        certificatefactory = CertificateFactory.getInstance("X.509");
    } catch (CertificateException e) {
        e.printStackTrace();
    }
    X509Certificate objcert509 = null;
    try {
        objcert509 = (X509Certificate)certificatefactory.generateCertificate(byteArrayInputStream);
    } catch (CertificateException e) {
        e.printStackTrace();
    }

    byte[] publicKey = objcert509.getPublicKey().getEncoded();
    return publicKey;
}

输出:[48, 86, 48, 16, 6, 7, 42, -122, 72, -50, 61, 2, 1, 6, 5, 43, -127, 4, 0, 10, 3, 66 , 0, 4, -2, 6, 1, -3, -114, 15, -55, -25, -65, 101, -90, 85, 7, 18, -43, -117, -13, - 124, 67, 29, -15, -70, 114, 37, 56, 75, 112, -41, -102, -18, -39, -26, -121, -100, 127, -25, 30, 37, 84, -112, 88, 73, -56, -97, -85, 7, -94, -27, -113, 38, 39, 40, 75, 76, 82, 106, 7, -68, 83, -127, -103, -52, 125, 89]

飞镖代码

 var base64Str = base64.decode(certificateValue);
var x509Certificate = x509UtilsLocal.crlDerToPem(base64Str);
X509CertificateData x509certificateData = X509Utils.x509CertificateFromPem(x509Certificate);
print("getPublicKeyFromCert" + hex.decode(x509certificateData.publicKeyData.bytes).toString());
var bytes = hex.decode(x509certificateData.publicKeyData.bytes);

输出:[0, 4, 254, 6, 1, 253, 142, 15, 201, 231, 191, 101, 166, 85, 7, 18, 213, 139, 243, 132, 67, 29, 241, 186, 114, 37, 56, 75, 112, 215, 154, 238, 217, 230, 135, 156, 127, 231, 30, 37, 84, 144, 88, 73, 200, 159, 171, 7, 162、229、143、38、39、40、75、76、82、106、7、188、83、129、153、204、125、89]

java dart x509certificate public-key pem
© www.soinside.com 2019 - 2024. All rights reserved.