Java SHA256withRSA digital signature for String with decimal values

Viewed 53

I have to get as input a json payload and sign it with SHA256withRSA . I'm trying to convert the json to java object , first when the value has an Integer type, the signature was correct but when I changed the type to Double as it is an amount , the generated signature string become wrong.

        byte[] b1 = Base64.getDecoder().decode(realPK);
        PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(b1);
        KeyFactory kf = KeyFactory.getInstance("RSA");
 
        Signature privateSignature = Signature.getInstance("SHA256withRSA");
        privateSignature.initSign(kf.generatePrivate(spec));
        privateSignature.update(input.getBytes("UTF-8"));
        byte[] s = privateSignature.sign();
        return Base64.getEncoder().encodeToString(s);
    }

Java Object

public class EmloyeeRecord {

......

@NotNull(message = "BasicSalary should not be empty") @JsonProperty("BasicSalary") public Double basicSalary; ... }

Json Payload

"FileRecordRq": [ { .... "BasicSalary": 378880.00, .... }

0 Answers
Related