All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.founder.ecrx.utils.BCUtils Maven / Gradle / Ivy

There is a newer version: 3.6.1.9
Show newest version
package com.founder.ecrx.utils;

import org.bouncycastle.jce.provider.BouncyCastleProvider;

import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException;
import java.security.*;

public class BCUtils {

    static {
        if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME)==null){
            Security.addProvider(new BouncyCastleProvider());
        }
    }

    public static Cipher getCipher(final String algorithm) {
        try {
            return Cipher.getInstance(algorithm, BouncyCastleProvider.PROVIDER_NAME);
        } catch (final NoSuchAlgorithmException | NoSuchPaddingException | NoSuchProviderException e) {
            throw new IllegalArgumentException(e);
        }
    }

    public static MessageDigest getMessageDigest(final String algorithm) {
        try {
            return MessageDigest.getInstance(algorithm, BouncyCastleProvider.PROVIDER_NAME);
        } catch (final NoSuchAlgorithmException|NoSuchProviderException e) {
            throw new IllegalArgumentException(e);
        }
    }
    public static Signature getSignature(final String algorithm) {
        try {
            return Signature.getInstance(algorithm, BouncyCastleProvider.PROVIDER_NAME);
        } catch (final NoSuchAlgorithmException|NoSuchProviderException e) {
            throw new IllegalArgumentException(e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy