Update: The critical aspect is that kp
(keypair) is generated "outside" this code. This code is an onclick function whereas kp
is defined in the code that sets up the onclick. Shouldn't matter but that's what seems to be the problem and that's inexplicable.
What's wrong with the following code? It always prints (logs) false for the verification b
even though the data is the same string "foo"
and the signature is the same one that was generateded earlier in the code sig
val sig = Signature.getInstance("SHA256withECDSA").run {
initSign(kp.private)
update("foo".toByteArray())
sign()
}
Log.d(tag, "sig: " + sig.toString())
val o = Signature.getInstance("SHA256withECDSA")
o.initVerify(kp.public)
o.update("foo".toByteArray())
val b = o.verify(sig)
Log.d(tag, b.toString())