Example usage for org.bouncycastle.tsp TSPAlgorithms SHA512

List of usage examples for org.bouncycastle.tsp TSPAlgorithms SHA512

Introduction

In this page you can find the example usage for org.bouncycastle.tsp TSPAlgorithms SHA512.

Prototype

ASN1ObjectIdentifier SHA512

To view the source code for org.bouncycastle.tsp TSPAlgorithms SHA512.

Click Source Link

Usage

From source file:be.fedict.eid.applet.service.signer.time.TSPTimeStampService.java

License:Open Source License

/**
 * Sets the digest algorithm used for time-stamping data. Example value:
 * "SHA-1"./*from  w  ww  .j  av a 2s  . c o m*/
 * 
 * @param digestAlgo
 */
public void setDigestAlgo(String digestAlgo) {
    if ("SHA-1".equals(digestAlgo)) {
        this.digestAlgoOid = TSPAlgorithms.SHA1;
    } else if ("SHA-256".equals(digestAlgo)) {
        this.digestAlgoOid = TSPAlgorithms.SHA256;
    } else if ("SHA-384".equals(digestAlgo)) {
        this.digestAlgoOid = TSPAlgorithms.SHA384;
    } else if ("SHA-512".equals(digestAlgo)) {
        this.digestAlgoOid = TSPAlgorithms.SHA512;
    } else {
        throw new IllegalArgumentException("unsupported digest algo: " + digestAlgo);
    }
    this.digestAlgo = digestAlgo;
}

From source file:es.mityc.firmaJava.ts.TSPAlgoritmos.java

License:LGPL

public static String getAlgName(String oid) {
    if (TSPAlgorithms.SHA1.equals(oid))
        return SHA1;
    else if (TSPAlgorithms.SHA256.equals(oid))
        return SHA2;
    else if (TSPAlgorithms.SHA224.equals(oid))
        return SHA224;
    else if (TSPAlgorithms.SHA256.equals(oid))
        return SHA256;
    else if (TSPAlgorithms.SHA384.equals(oid))
        return SHA384;
    else if (TSPAlgorithms.SHA512.equals(oid))
        return SHA512;
    return oid;//from  w  w w .j  a v  a2 s  . c o m
}

From source file:es.mityc.firmaJava.ts.TSPAlgoritmos.java

License:LGPL

public static String getOID(String algoritmo) {

    Set permitidos = new HashSet(Arrays.asList(getValoresPermitidos()));

    if (permitidos.contains(algoritmo)) {
        if (SHA1.equals(algoritmo))
            return TSPAlgorithms.SHA1;
        else if (SHA2.equals(algoritmo))
            return TSPAlgorithms.SHA256;
        else if (SHA224.equals(algoritmo))
            return TSPAlgorithms.SHA224;
        else if (SHA256.equals(algoritmo))
            return TSPAlgorithms.SHA256;
        else if (SHA384.equals(algoritmo))
            return TSPAlgorithms.SHA384;
        else if (SHA512.equals(algoritmo))
            return TSPAlgorithms.SHA512;
    }// w  w  w  .  jav a  2 s.  co  m
    return null;
}

From source file:org.demoiselle.signer.timestamp.connector.TimeStampOperator.java

License:Open Source License

/**
 * Creates a time stamp request, signed with the users's certificate.
 *
 * @param privateKey private key to sign with
 * @param certificates certificate chain
 * @param content  set null if signing only hash
 * @param hash  set null if signing content
 * @return A time stamp request//from ww w .j a v a2s.  co m
 * @throws CertificateCoreException exception
 */
public byte[] createRequest(PrivateKey privateKey, Certificate[] certificates, byte[] content, byte[] hash)
        throws CertificateCoreException {
    try {
        logger.info(timeStampMessagesBundle.getString("info.timestamp.digest"));
        Digest digest = DigestFactory.getInstance().factoryDefault();
        String varAlgoOid = null;
        String varAlgo = null;
        if (Configuration.getInstance().getSO().toLowerCase().indexOf("indows") > 0) {
            logger.info(timeStampMessagesBundle.getString("info.timestamp.winhash"));
            varAlgoOid = TSPAlgorithms.SHA256.getId();
            varAlgo = "SHA256withRSA";
            digest.setAlgorithm(DigestAlgorithmEnum.SHA_256);
        } else {
            logger.info(timeStampMessagesBundle.getString("info.timestamp.linuxhash"));
            varAlgoOid = TSPAlgorithms.SHA512.getId();
            varAlgo = "SHA512withRSA";
            digest.setAlgorithm(DigestAlgorithmEnum.SHA_512);
        }

        byte[] hashedMessage = null;
        if (content != null) {
            hashedMessage = digest.digest(content);
            //logger.info(Base64.toBase64String(hashedMessage));   
        } else {
            hashedMessage = hash;
        }
        logger.info(timeStampMessagesBundle.getString("info.timestamp.prepare.request"));
        TimeStampRequestGenerator timeStampRequestGenerator = new TimeStampRequestGenerator();
        timeStampRequestGenerator
                .setReqPolicy(new ASN1ObjectIdentifier(TimeStampConfig.getInstance().getTSPOid()));
        timeStampRequestGenerator.setCertReq(true);
        BigInteger nonce = BigInteger.valueOf(100);
        timeStampRequest = timeStampRequestGenerator.generate(new ASN1ObjectIdentifier(varAlgoOid),
                hashedMessage, nonce);
        byte request[] = timeStampRequest.getEncoded();
        logger.info(timeStampMessagesBundle.getString("info.timestamp.sign.request"));
        RequestSigner requestSigner = new RequestSigner();
        byte[] signedRequest = requestSigner.signRequest(privateKey, certificates, request, varAlgo);
        return signedRequest;
    } catch (IOException ex) {

        throw new CertificateCoreException(ex.getMessage());
    }
}

From source file:org.signserver.module.tsa.TimeStampSignerTest.java

License:Open Source License

/**
 * Utility method to return the hash length for the hash types we're testing against
 * /*from  ww  w.  ja v  a 2  s .  co  m*/
 * @param hashType
 * @return
 */
private int getHashLength(ASN1ObjectIdentifier hashType) {
    if (TSPAlgorithms.SHA1.equals(hashType)) {
        return 20;
    } else if (TSPAlgorithms.SHA256.equals(hashType)) {
        return 32;
    } else if (TSPAlgorithms.SHA512.equals(hashType)) {
        return 64;
    } else if (TSPAlgorithms.RIPEMD160.equals(hashType)) {
        return 20;
    } else {
        LOG.info("Trying to use an unknow hash algorithm, using dummy length");
        // return the length of a SHA1 hash as a dummy value to allow passing
        // invalid hash algo names for testing
        return 20;
    }
}

From source file:org.signserver.module.tsa.TimeStampSignerTest.java

License:Open Source License

/**
 * Test requesting a timestamp with SHA512 as the hash algorithm
 * // w ww  .  ja v a 2s  .c om
 * @param worker
 * @throws Exception
 */
@Test
public void test07HashSHA512() throws Exception {
    testWithHash(TSPAlgorithms.SHA512);
}