1

I am trying to create a digital signature. when i console log this signature i get weird characters like this :

1��N�U]*������gڇ��Xр��ӶhR���1��q

My friend is making the backend to check this digital signature only his signatures are hexadecimal. His signature looks like:

3BFC368C044C932FB62746765A84F3C3ABE7913CC8FDDB32DDF94607D99BE754D8761FAC1E9314B80E1E5EB14D936E137CB44954F245E1D38A6F4FDC80DB00B5D953DDF0A9E533FADD574F116DDA36AF517217753AA98F284BE946739641EE26933DC8E72B10CAA0D75984D5B1561A3B84815D1BFC9910F2316E0A0773F2CFE9F139D7C9A5D0CE45256055A63A80BDE6B5DF7F433AFE803E251E7F19964F93F008A7B7AA4A488BD4FB4968AE82D1D6DF6EBB2DA000F6F798808888D040EC84FB285095387EB8AA9397CB2FAC0248D2D5277386432D99E55AAAD5C3E79048C64713A695B575FD89D3B4218FA784F2116A80B359D4FF62F0391F1EFAC7968DAAA

Is it possible to Sign a signature in java as a hexadecimal?

Android:

            KeyFactory kf = KeyFactory.getInstance("RSA");
            PrivateKey privKey = kf.generatePrivate(keySpec);
            System.out.println(privKey);
            Signature signer = Signature.getInstance("SHA256withRSA");
            signer.initSign(privKey);
            signer.update(hash.getBytes());
            byte[] signature = signer.sign();
            String encryptHash = new String(signature);
Michael
  • 33
  • 4
  • 2
    have you tried something like this? i dont think you should be converting directly from byte to string. https://stackoverflow.com/a/9855338/4111447 – Tomer Shemesh Jun 18 '19 at 12:45

1 Answers1

2

You have an array of Byte, you need to convert each byte to their hexadecimal representation, you can do something like:

byte[] signature = signer.sign();
StringBuilder hexBuilder = new StringBuilder();
for(b: signature){
    hexBuilder.append(String.format("%02x", b));
}
String hexSignature = hexBuilder.toString();
  • Thnx for this. i get the Signature in HEX atm but i doesn't verify at the backend side so i can go and check that thnx anyway – Michael Jun 18 '19 at 13:14