Created
October 3, 2023 06:46
-
-
Save whytarun/39d992154d625fbc1333be11116a53d2 to your computer and use it in GitHub Desktop.
SSL Support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CertificateHelper @Inject constructor(@ApplicationContext context: Context) { | |
private val applicationContext = context | |
fun createTrustManagers(): Array<TrustManager> { | |
val certificateInputStream = applicationContext.resources.openRawResource( | |
R.raw.test) | |
val certificateFactory = CertificateFactory.getInstance("X.509") | |
val certificate = certificateFactory.generateCertificate(certificateInputStream) | |
val trustManagerFactory = TrustManagerFactory.getInstance( | |
TrustManagerFactory.getDefaultAlgorithm()) | |
val keyStore = KeyStore.getInstance(KeyStore.getDefaultType()) | |
keyStore.load(null) | |
keyStore.setCertificateEntry("test", certificate) | |
trustManagerFactory.init(keyStore) | |
return trustManagerFactory.trustManagers | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment