Example usage for java.security Security addProvider

List of usage examples for java.security Security addProvider

Introduction

In this page you can find the example usage for java.security Security addProvider.

Prototype

public static int addProvider(Provider provider) 

Source Link

Document

Adds a provider to the next position available.

Usage

From source file:test.integ.be.agiv.security.BeIDTest.java

@Test
public void testReadAuthnCert() throws Exception {
    Security.addProvider(new BeIDProvider());
    KeyStore keyStore = KeyStore.getInstance("BeID");
    keyStore.load(null);/*from  w ww  . j  a  v a 2  s .c  o m*/
    Certificate certificate = keyStore.getCertificate("Authentication");
    LOG.debug("certificate: " + certificate);
    Certificate caCert = keyStore.getCertificate("CA");
    LOG.debug("CA cert: " + caCert);
    Certificate rootCert = keyStore.getCertificate("Root");
    LOG.debug("root cert: " + rootCert);

    File tmpFile = File.createTempFile("beid-authn-", ".der");
    FileUtils.writeByteArrayToFile(tmpFile, certificate.getEncoded());
    LOG.debug("cert file: " + tmpFile.getAbsolutePath());

    File caTmpFile = File.createTempFile("gov-ca-", ".der");
    FileUtils.writeByteArrayToFile(caTmpFile, caCert.getEncoded());
    LOG.debug("ca cert file: " + caTmpFile.getAbsolutePath());

    File rootTmpFile = File.createTempFile("root-ca-", ".der");
    FileUtils.writeByteArrayToFile(rootTmpFile, rootCert.getEncoded());
    LOG.debug("root cert file: " + rootTmpFile.getAbsolutePath());
}

From source file:io.getlime.security.powerauth.app.rest.api.spring.ServletInitializer.java

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    Security.addProvider(new BouncyCastleProvider());
    PowerAuthConfiguration.INSTANCE.setKeyConvertor(CryptoProviderUtilFactory.getCryptoProviderUtils());
    return application.sources(PowerAuthApiJavaApplication.class);
}

From source file:com.jamesashepherd.sshproxyj.core.Start.java

@Override
public void startup() throws StartException {
    logger.info("sshproxyj starting");
    Security.addProvider(new BouncyCastleProvider());
    context = new FileSystemXmlApplicationContext(getSpringConfigURL());
}

From source file:test.unit.be.fedict.eid.dss.document.xml.XMLDSSDocumentServiceLargeTest.java

@BeforeClass
public static void setUp() {
    if (null == Security.getProvider(BouncyCastleProvider.PROVIDER_NAME)) {
        Security.addProvider(new BouncyCastleProvider());
    }/*from  ww  w. j a  v a 2 s.  c  o  m*/
    //Init.init();
}

From source file:test.unit.be.fedict.eid.applet.service.signer.AbstractCMSSignatureServiceTest.java

@BeforeClass
public static void beforeClass() {
    if (null == Security.getProvider(BouncyCastleProvider.PROVIDER_NAME)) {
        Security.addProvider(new BouncyCastleProvider());
    }//from www  .j  a  va  2  s  .c  o m
}

From source file:eu.mrbussy.security.crypto.pgp.PGPDecryptorTest.java

@Before
public void setUp() throws Exception {
    Security.addProvider(new BouncyCastleProvider());
    privateKey = PGPDecryptor.class.getResource("/test.priv.gpg").getFile();
    privateMessagePath = PGPDecryptor.class.getResource("/message.txt.private").getFile();
    privateMessageStream = PGPDecryptor.class.getResourceAsStream("/message.txt.private");
}

From source file:test.integ.be.fedict.trust.BelgiumRootCA2v2.java

@Before
public void setUp() throws Exception {
    Security.addProvider(new BouncyCastleProvider());
}

From source file:org.aon.esolutions.appconfig.client.util.RSAEncryptUtil.java

/**
 * Init java security to add BouncyCastle as an RSA provider
 *///from  w w w  .  j  av a 2s. c  o  m
public static void init() {
    Security.addProvider(new BouncyCastleProvider());
}

From source file:com.jamesashepherd.sshproxyj.core.StartTest.java

@BeforeClass
static public void setUp() throws SshProxyJException, IOException {
    Security.addProvider(new BouncyCastleProvider());
    System.setProperty("org.slf4j.simpleLogger.log.com.jamesashepherd", "debug");
    keyPair = KeyUtils.makeKeyPair(UtilsTest.testPublicKey(), UtilsTest.testPrivateKey());
    keyPair2 = KeyUtils.makeKeyPair(UtilsTest.test2PublicKey(), UtilsTest.test2PrivateKey());
}

From source file:edu.ku.brc.helpers.Encryption.java

/** I am leaving this here for documentation purposes
 * @param args input from the command line
 * @throws Exception some error/* w ww  . ja va  2s .c o m*/
 */
public static void main(final String[] args) throws Exception {
    /*
     * If we're configured to use a third-party cryptography provider, where that provider is
     * not permanently installed, then we need to install it first.
     */
    if (EXTRA_PROVIDER != null) {
        Provider prov = (Provider) Class.forName(EXTRA_PROVIDER).newInstance();
        Security.addProvider(prov);
    }

    /*
     * The Encryption() function above uses a byte[] as input, so it's more general (it can Encryption
     * anything, not just a String), as well as using a char[] for the password, because it can
     * be overwritten once it's finished. Strings are immutable, so to purge them from RAM you
     * have to hope they get garbage collected and then the RAM gets reused. For char[]s you can
     * simply fill up the array with junk to erase the password from RAM. Anyway, use char[] if
     * you're concerned about security, but for a test case, a String works fine.
     */
    /* Our input text and password. */
    String input = "Hello World!"; //$NON-NLS-1$
    String password = "abcd"; //$NON-NLS-1$

    byte[] inputBytes = input.getBytes();
    char[] passwordChars = password.toCharArray();

    /* Encrypt the data. */
    byte[] ciphertext = encrypt(inputBytes, passwordChars);

    System.out.println("Ciphertext:"); //$NON-NLS-1$

    /*
     * This is just a little loop I made up which displays the encrypted data in hexadecimal, 30
     * bytes to a line. Obviously, the ciphertext won't necessarily be a recognizable String,
     * and it'll probably have control characters and such in it. We don't even want to convert
     * it to a String, let alone display it onscreen. If you need text, investigate some kind of
     * encoding at this point on top of the encryption, like Base64. It's not that hard to
     * implement and it'll give you text to carry from place to place. Just remember to *de*code
     * the text before calling decrypt().
     */
    int i;
    for (i = 0; i < ciphertext.length; i++) {
        String s = Integer.toHexString(ciphertext[i] & 0xFF);
        if (s.length() == 1)
            s = "0" + s; //$NON-NLS-1$
        System.out.print(s);
        if (i % 30 == 29)
            System.out.println();
    }
    if ((ciphertext.length - 1) % 30 != 29)
        System.out.println();

    String hexText = makeHEXStr(ciphertext);
    System.out.println("To:   [" + hexText + "]"); //$NON-NLS-1$ //$NON-NLS-2$
    System.out.println("From: [" + reverseHEXStr(hexText) + "]****"); //$NON-NLS-1$ //$NON-NLS-2$

    /*
     * Now, decrypt the data. Note that all we need is the password and the ciphertext.
     */
    byte[] output = decrypt(ciphertext, passwordChars);

    /* Transform the output into a string. */
    String sOutput = new String(output);

    /* Display it. */
    System.out.println("Plaintext:\n" + sOutput); //$NON-NLS-1$
}