All Downloads are FREE. Search and download functionalities are using the official Maven repository.

top.rwocj.wx.pay.core.DefaultV3Sign Maven / Gradle / Ivy

There is a newer version: 0.8-javax
Show newest version
package top.rwocj.wx.pay.core;


import java.security.*;
import java.util.Base64;

public class DefaultV3Sign implements Sign {

    private final PrivateKey privateKey;

    public DefaultV3Sign(PrivateKey privateKey) {
        this.privateKey = privateKey;
    }

    @Override
    public String sign(byte[] message) {
        try {
            Signature sign = Signature.getInstance("SHA256withRSA");
            sign.initSign(privateKey);
            sign.update(message);
            return Base64.getEncoder().encodeToString(sign.sign());
        } catch (SignatureException | InvalidKeyException | NoSuchAlgorithmException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy