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