File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed
android/src/main/java/com/github/emotokcak/reactnative/mqtt Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -51,12 +51,17 @@ object PEMLoader {
5151 */
5252 @JvmStatic
5353 fun loadPrivateKeyFromString (pem : String ): PrivateKey {
54+ val isRSA = pem.startsWith(" -----BEGIN RSA PRIVATE KEY-----" )
5455 val pemContents = pem
5556 .replace(" -----BEGIN RSA PRIVATE KEY-----" , " " )
5657 .replace(" -----END RSA PRIVATE KEY-----" , " " )
58+ .replace(" -----BEGIN EC PRIVATE KEY-----" , " " )
59+ .replace(" -----END EC PRIVATE KEY-----" , " " )
60+ .replace(" -----BEGIN PRIVATE KEY-----" , " " )
61+ .replace(" -----END PRIVATE KEY-----" , " " )
5762 val data = Base64 .getMimeDecoder().decode(pemContents)
5863 val keySpec = PKCS8EncodedKeySpec (data)
59- val keyFactory = KeyFactory .getInstance(" RSA" )
64+ val keyFactory = KeyFactory .getInstance(if (isRSA) " RSA" else " EC " )
6065 return keyFactory.generatePrivate(keySpec)
6166 }
6267}
You can’t perform that action at this time.
0 commit comments