I am trying to implement PS256 verification in android over Kotlin using BouncyCastle. I have read the documentation of BouncyCastle where they list SHA256withRSAandMGF1 as an available algorithm in their library but when running, I am getting not such algorithm found exception. Can someone help with this?
fun verifySignedContent(cert: String, jwtS: String): Boolean {
val certFactory: CertificateFactory = CertificateFactory.getInstance("X.509")
val bytes = ByteArrayInputStream(cert.toByteArray())
Security.addProvider(BouncyCastleProvider())
val signedJWT = SignedJWT.parse(jwtS)
val signature = signedJWT.signature
val sig = Signature.getInstance("SHA256withRSAandMGF1", "BC")
println("Signature: " + signature.toJSONString())
sig.initVerify(certFactory.generateCertificate(bytes))
sig.update(signature.decode())
val flagSig = sig.verify(signedJWT.signature.decode())
println("Signature is valid: $flagSig")
return flagSig
}
I have added the following dependencies in my Build.gradle
implementation 'org.bouncycastle:bcprov-jdk18on:1.71'
implementation 'org.bouncycastle:bcpkix-jdk18on:1.71'