public String sign(String msg) {
        try {
            RSAPrivateKey key = getPrivateKey();
            Signature sig = Signature.getInstance(SIGNING_ALGORITHM + "with" + key.getAlgorithm());
            sig.initSign(key);
            sig.update(msg.getBytes(StandardCharsets.UTF_8));
            return Base64.getEncoder().encodeToString(sig.sign());
        } catch (GeneralSecurityException e) {
            throw new SecurityException(e);
        }
    }
@Test
    public void dsigSignAndVerify() throws Exception {
        String plainText = "Hello world";
        String msg = key.sign(plainText);
        System.out.println(msg);

        Signature sig = Signature.getInstance("SHA256withRSA");
        sig.initVerify(key.getPublicKey());
        sig.update(plainText.getBytes(StandardCharsets.UTF_8));

        assertTrue(sig.verify(Base64.getDecoder().decode(msg)));
    }