I need to verify a signature with Java/Android and an ATEC108A Chip which is created in a .Net environment. (Using SunEC and AndroidOpenSSL)
The signature is created in .Net using BCrypt, the keys are also created using BCrypt and stored on the Microsoft key store. The signature and public key can sent to the AT chip and it verifies, however it does not work on Android.
Key / Signature Process:
The public key is exported from BCrypt in the x.509 key format which includes the identifiers for SHA256-ECDSA and the curve prime256v1 resulting in:
3059301306072A8648CE3D020106082A 8648CE3D03010703420004368711132B BDB4C6D03F7DF4F4688F5F4F21A3B30B EB1016648555A25B27C915CAB5C26B98 0FF792A0090BF1E131C175D9C66C8D79 3476489770869E09273816
The signature from BCrypt is in the 64-byte format, but android requires the sequence and length identifiers resulting in the signature as follows:
304502201 BD91B39A7447724223A4B3E9070A6FD5 33360F96B072998058AA73E572F48D80 22100 ED0BDC731080CFC82C8B8FB37D74CC18 3820343C2756671F0E1D813E469DD3D7
The message that has been used to sign and verify is "Hello World" which hashed is:
A591A6D40BF420404A011733CFB7B190 D62C65BF0BCDA32B57B277D9AD9F146E
Android Process:
Create the X509 key spec and public key from the above key byte array:
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(encoded); KeyFactory kf = KeyFactory.getInstance("EC", "AndroidOpenSSL"); pubKey = kf.generatePublic(keySpec);
Create signature using the AndroidOpenSSL provider:
Signature signature; signature = Signature.getInstance("SHA256withECDSA", "AndroidOpenSSL"); signature.initVerify(pubKey);
Load the above hash array:
signature.update(hash);
Verify the above signature:
signature.verify(sign);
The signature and key above checks out on the AT chip (Also verified on ECDSA Sample which runs JavaScript-OpenSSL) but does not verify with AndroidOpenSSL. Am I missing something simple or where can the problem be?
The public key structure checks out on ASN.1 decoder and load successfully within the code (extracted and checked from the public key), the signature is in the expected format for Java and the hash values are the same on both sides.