Hi,
I want to encrypt a string with a certificate *.cer (valid, tested on other platforms). I also tried with a .der file, but it didn't work.
Reading the public key :
Encrypting :
The exception is :
java.security.spec.InvalidKeySpecException: java.lang.RuntimeException: error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag
I can't find why,
Thanks
I want to encrypt a string with a certificate *.cer (valid, tested on other platforms). I also tried with a .der file, but it didn't work.
Reading the public key :
B4X:
PUBLIC_KEY = File.ReadString(File.DirAssets,"mycertificate.cer").GetBytes("UTF8")
Encrypting :
B4X:
Sub CryptWithPublicKey(input As String) As String
Dim cipher_ As Cipher
Dim key_ As KeyPairGenerator
Dim msg(0) As Byte
Dim Bconv As ByteConverter
key_.Initialize("RSA",128)
key_.PublicKeyFromBytes(Main.PUBLIC_KEY) ' Here's the exception
cipher_.Initialize("RSA")
msg = cipher_.Encrypt(input.GetBytes("UTF8"),key_,False)
Return Bconv.StringFromBytes(msg,"UTF8")
End Sub
The exception is :
java.security.spec.InvalidKeySpecException: java.lang.RuntimeException: error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag
I can't find why,
Thanks