Convert PHP RSA PublicKey into Android PublicKey

前端 未结 2 1188
失恋的感觉
失恋的感觉 2020-12-16 07:19

I am working on a client server based application.

Where I get PublicKey in this format

\"enter

2条回答
  •  失恋的感觉
    2020-12-16 08:07

    There is a project called "bouncycastle" we use it on j2me but it woll work on android too. it can be used to handle openssl certificates.

    bouncycastle.org

    Java KeyStore implementation:

    import java.security.cert.Certificate import java.security.KeyStore

    and readme a LOT because openssl keys are not directly supported by java which is bringing their own mechanisms.

    Java example for KeyStore stuff:

    byte[] certData = ...       
    /* create KeyStore */
    KeyStore ks = KeyStore.getInstance("JKS", "SUN");
    /* load key store (initialization */
    ks.load(null, null);
    /* create CertificateFactory */
    CertificateFactory cf = CertificateFactory.getInstance("X509");
    /* create certificate from input stream */
    Certificate cert;
    /* provide cert data */
    ByteArrayInputStream in = new ByteArrayInputStream(makeCert(certData));
    
    
    
    private static byte[] makeCert(byte[] data) {
        String headline = "-----BEGIN CERTIFICATE-----";
        String footline = "-----END CERTIFICATE-----";
    
        String certStr = headline;
        for (int i = 0; i < data.length; i++) {
            if (i%64 == 0) {
                certStr += "\n";
            }
            certStr += (char)data[i];
        }
        if ((data.length-1)%64 != 0) {
            certStr += "\n";
        }
        certStr += footline;
        return certStr.getBytes();
    }
    

提交回复
热议问题