Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.google.code.springcryptoutils.core.signature;
 
 
 import java.util.Map;

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

Author(s):
Mirko Caserta (mirko.caserta@gmail.com)
    private Map<StringSignercache = new HashMap<StringSigner>();
    private String algorithm = "SHA1withRSA";

    
Sets the private key registry by alias.

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

    
The signature algorithm. The default is SHA1withRSA.

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

    
Signs a message.

Parameters:
keyStoreChooser the keystore chooser
privateKeyChooserByAlias the private key chooser
message the message to sign
Returns:
the signature
    public byte[] sign(KeyStoreChooser keyStoreChooserPrivateKeyChooserByAlias privateKeyChooserByAliasbyte[] message) {
        Signer signer = .get(cacheKey(keyStoreChooserprivateKeyChooserByAlias));
        if (signer != null) {
            return signer.sign(message);
        }
        SignerImpl signerImpl = new SignerImpl();
        signerImpl.setAlgorithm();
        PrivateKey privateKey = .get(keyStoreChooserprivateKeyChooserByAlias);
        if (privateKey == null) {
            throw new SignatureException("private key not found in registry: keyStoreName=" + keyStoreChooser.getKeyStoreName() + ", alias=" + privateKeyChooserByAlias.getAlias());
        }
        signerImpl.setPrivateKey(privateKey);
        .put(cacheKey(keyStoreChooserprivateKeyChooserByAlias), signerImpl);
        return signerImpl.sign(message);
    }
    private static String cacheKey(KeyStoreChooser keyStoreChooserPrivateKeyChooserByAlias privateKeyChooserByAlias) {
        return new StringBuffer()
                .append(keyStoreChooser.getKeyStoreName())
                .append('-')
                .append(privateKeyChooserByAlias.getAlias())
                .toString();
    }
New to GrepCode? Check out our FAQ X