Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 import java.util.Map;

The default implementation for providing base64 encoded digital signatures when the private key alias can be configured on the side of the user of this interface.

Mirko Caserta (
    private String algorithm = "SHA1withRSA";
    private String charsetName = "UTF-8";

Sets the private key registry by alias.

privateKeyRegistryByAlias the private key registry by alias
    public void setPrivateKeyRegistryByAlias(PrivateKeyRegistryByAlias privateKeyRegistryByAlias) {
        this. = privateKeyRegistryByAlias;

The signature algorithm. The default is SHA1withRSA.

algorithm the signature algorithm
    public void setAlgorithm(String algorithm) {
        this. = algorithm;

The charset to use when converting a string into a raw byte array representation. The default is UTF-8.

charsetName the charset name (default: UTF-8)
    public void setCharsetName(String charsetName) {
        this. = charsetName;

Signs a message.

keyStoreChooser the keystore chooser
privateKeyChooserByAlias the private key chooser
message the message to sign
the base64 encoded signature
    public String sign(KeyStoreChooser keyStoreChooserPrivateKeyChooserByAlias privateKeyChooserByAliasString message) {
        Base64EncodedSigner signer = .get(cacheKey(keyStoreChooserprivateKeyChooserByAlias));
        if (signer != null) {
            return signer.sign(message);
        Base64EncodedSignerImpl signerImpl = new Base64EncodedSignerImpl();
        PrivateKey privateKey = .get(keyStoreChooserprivateKeyChooserByAlias);
        if (privateKey == null) {
            throw new SignatureException("private key not found: keyStoreName=" + keyStoreChooser.getKeyStoreName() + ", alias=" + privateKeyChooserByAlias.getAlias());
        .put(cacheKey(keyStoreChooserprivateKeyChooserByAlias), signerImpl);
        return signerImpl.sign(message);
    private static String cacheKey(KeyStoreChooser keyStoreChooserPrivateKeyChooserByAlias privateKeyChooserByAlias) {
        return new StringBuffer()
New to GrepCode? Check out our FAQ X