What issues should I pay attention to when using the rsa key generated by phpopenssl for android and ios?

Source: Internet
Author: User
One project requires php to produce rsa honeymoon for android and ios through openssl. It has been debugging for two days now, and there has been a problem when using the key on the android side. {Code ...} this is one of the errors encountered by android. below is the code for generating the key {code ...... one project requires php to produce rsa honeymoon for android and ios through openssl. It has been debugging for two days now, and there has been a problem when using the key on the android side.

    X509EncodedKeySpec expects DER-encoded data, not PEM-encoded

This is one of the errors that android encounters.

Below is my code for generating the key

    // generate 2048-bit RSA key    $config = array(        'private_key_bits' => $length,        'private_key_type' => OPENSSL_KEYTYPE_RSA    );    $pkGenerate = openssl_pkey_new($config);    // get the private key    openssl_pkey_export($pkGenerate,$pkGeneratePrivate); // NOTE: second argument is passed by reference    // get the public key    $pkGenerateDetails = openssl_pkey_get_details($pkGenerate);    $pkGeneratePublic = $pkGenerateDetails['key'];    // free resources    openssl_pkey_free($pkGenerate);    // fetch/import public key from PEM formatted string    // remember $pkGeneratePrivate now is PEM formatted...    // this is an alternative method from the public retrieval in previous    $pkImport = openssl_pkey_get_private($pkGeneratePrivate); // import    $pkImportDetails = openssl_pkey_get_details($pkImport); // same as getting the public key in previous    $pkImportPublic = $pkImportDetails['key'];    openssl_pkey_free($pkImport); // clean up    return array('public'=>$pkGeneratePublic,'private'=>$pkGeneratePrivate);

I didn't know much about rsa encryption before. Today is the first time I used it, And I encountered this cross-language problem. I can use the generated key for encryption and decryption.
For more information, see.

Here is an article that is very similar to the question I asked, but I am not familiar with rsa and openssl, so I cannot understand what I mentioned in the article. For more information, see.
Http://security.stackexchange.com/questions/15948/how-to-supply-openssl-generated-private-public-keys-to-ios-android-apps

Reply content:

One project requires php to produce rsa honeymoon for android and ios through openssl. It has been debugging for two days now, and there has been a problem when using the key on the android side.

    X509EncodedKeySpec expects DER-encoded data, not PEM-encoded

This is one of the errors that android encounters.

Below is my code for generating the key

    // generate 2048-bit RSA key    $config = array(        'private_key_bits' => $length,        'private_key_type' => OPENSSL_KEYTYPE_RSA    );    $pkGenerate = openssl_pkey_new($config);    // get the private key    openssl_pkey_export($pkGenerate,$pkGeneratePrivate); // NOTE: second argument is passed by reference    // get the public key    $pkGenerateDetails = openssl_pkey_get_details($pkGenerate);    $pkGeneratePublic = $pkGenerateDetails['key'];    // free resources    openssl_pkey_free($pkGenerate);    // fetch/import public key from PEM formatted string    // remember $pkGeneratePrivate now is PEM formatted...    // this is an alternative method from the public retrieval in previous    $pkImport = openssl_pkey_get_private($pkGeneratePrivate); // import    $pkImportDetails = openssl_pkey_get_details($pkImport); // same as getting the public key in previous    $pkImportPublic = $pkImportDetails['key'];    openssl_pkey_free($pkImport); // clean up    return array('public'=>$pkGeneratePublic,'private'=>$pkGeneratePrivate);

I didn't know much about rsa encryption before. Today is the first time I used it, And I encountered this cross-language problem. I can use the generated key for encryption and decryption.
For more information, see.

Here is an article that is very similar to the question I asked, but I am not familiar with rsa and openssl, so I cannot understand what I mentioned in the article. For more information, see.
Http://security.stackexchange.com/questions/15948/how-to-supply-openssl-generated-private-public-keys-to-ios-android-apps

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.