Example usage for org.bouncycastle.crypto.signers PSSSigner generateSignature

List of usage examples for org.bouncycastle.crypto.signers PSSSigner generateSignature

Introduction

In this page you can find the example usage for org.bouncycastle.crypto.signers PSSSigner generateSignature.

Prototype

public byte[] generateSignature() throws CryptoException, DataLengthException 

Source Link

Document

generate a signature for the message we've been loaded with using the key we were initialised with.

Usage

From source file:dorkbox.util.crypto.CryptoRSA.java

License:Apache License

/**
 * RSA sign data with a specified key.//from  w  w  w  . ja v a  2 s.c o m
 *
 * @param logger
 *                 may be null, if no log output is necessary
 *
 * @return empty byte[] if error
 */
public static byte[] sign(PSSSigner signer, RSAPrivateCrtKeyParameters rsaPrivateKey, byte[] mesg,
        Logger logger) {
    signer.init(true, rsaPrivateKey);
    signer.update(mesg, 0, mesg.length);

    try {
        return signer.generateSignature();
    } catch (Exception e) {
        if (logger != null) {
            logger.error("Unable to perform RSA cipher.", e);
        }
        return new byte[0];
    }
}