Example usage for java.security InvalidKeyException getCause

List of usage examples for java.security InvalidKeyException getCause

Introduction

In this page you can find the example usage for java.security InvalidKeyException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:com.xinferin.licensing.LicenceGenerator.java

/**
 * Signs the data and returns the signature.
 * @param toBeSigned Data to be signed//from   w  w  w. j a  v a 2 s. c  o m
 * @return byte[] Signature
 * @throws Exception 
*/
public byte[] signData(byte[] toBeSigned) throws Exception {

    try {
        if (privateKey == null)
            initialisePrivateKey();

        Signature signatureInstance = Signature.getInstance("SHA1withRSA");
        signatureInstance.initSign(privateKey);
        signatureInstance.update(toBeSigned);

        return signatureInstance.sign();

    } catch (NoSuchAlgorithmException ex) {
        throw new Exception("The SHA1withRSA algorithm was not found. " + ex.getCause());
    } catch (InvalidKeyException in) {
        throw new Exception("Invalid key returned from database. " + in.getCause());
    } catch (SignatureException se) {
        throw new Exception("No signature instance can be created. " + se.getCause());
    }
}

From source file:org.apache.hadoop.fs.azure.SendRequestIntercept.java

/**
 * Handler which processes the sending request event from Azure SDK. The
 * handler simply sets reset the conditional header to make all read requests
 * unconditional if reads with concurrent OOB writes are allowed.
 * /*from   w  w  w  .jav a2 s. com*/
 * @param sendEvent
 *          - send event context from Windows Azure SDK.
 */
@Override
public void eventOccurred(SendingRequestEvent sendEvent) {

    if (!(sendEvent.getConnectionObject() instanceof HttpURLConnection)) {
        // Pass if there is no HTTP connection associated with this send
        // request.
        return;
    }

    // Capture the HTTP URL connection object and get size of the payload for
    // the request.
    HttpURLConnection urlConnection = (HttpURLConnection) sendEvent.getConnectionObject();

    // Determine whether this is a download request by checking that the request
    // method
    // is a "GET" operation.
    if (urlConnection.getRequestMethod().equalsIgnoreCase("GET") && isOutOfBandIoAllowed()) {
        // If concurrent reads on OOB writes are allowed, reset the if-match
        // condition on the conditional header.
        urlConnection.setRequestProperty(HeaderConstants.IF_MATCH, ALLOW_ALL_REQUEST_PRECONDITIONS);

        // In the Java AzureSDK the packet is signed before firing the
        // SendRequest. Setting
        // the conditional packet header property changes the contents of the
        // packet, therefore the packet has to be re-signed.
        try {
            // Sign the request. GET's have no payload so the content length is
            // zero.
            StorageCredentialsHelper.signBlobAndQueueRequest(getCredentials(), urlConnection, -1L,
                    getOperationContext());
        } catch (InvalidKeyException e) {
            // Log invalid key exception to track signing error before the send
            // fails.
            String errString = String.format(
                    "Received invalid key exception when attempting sign packet." + " Cause: %s",
                    e.getCause().toString());
            LOG.error(errString);
        } catch (StorageException e) {
            // Log storage exception to track signing error before the call fails.
            String errString = String.format(
                    "Received storage exception when attempting to sign packet." + " Cause: %s",
                    e.getCause().toString());
            LOG.error(errString);
        }
    }
}