Example usage for org.bouncycastle.jce.provider BouncyCastleProvider BouncyCastleProvider

List of usage examples for org.bouncycastle.jce.provider BouncyCastleProvider BouncyCastleProvider

Introduction

In this page you can find the example usage for org.bouncycastle.jce.provider BouncyCastleProvider BouncyCastleProvider.

Prototype

public BouncyCastleProvider() 

Source Link

Document

Construct a new provider.

Usage

From source file:com.netflix.msl.keyx.JsonWebEncryptionLadderExchangeSuite.java

License:Open Source License

@BeforeClass
public static synchronized void setup()
        throws MslEncodingException, MslCryptoException, NoSuchAlgorithmException, MslEntityAuthException {
    if (pskCtx == null) {
        Security.addProvider(new BouncyCastleProvider());

        pskCtx = new MockMslContext(EntityAuthenticationScheme.PSK, false);

        // Create PSK wrapping crypto context.
        {//from   w  w w . j  a  v a 2  s . c o m
            final EntityAuthenticationData entityAuthData = pskCtx.getEntityAuthenticationData(null);
            final EntityAuthenticationFactory entityAuthFactory = pskCtx
                    .getEntityAuthenticationFactory(entityAuthData.getScheme());
            final ICryptoContext pskCryptoContext = entityAuthFactory.getCryptoContext(pskCtx, entityAuthData);
            final CekCryptoContext wrapCekCryptoContext = new AesKwCryptoContext(pskCryptoContext);
            PSK_CRYPTO_CONTEXT = new JsonWebEncryptionCryptoContext(pskCtx, wrapCekCryptoContext,
                    Encryption.A128GCM, Format.JWE_JS);
        }

        // The wrap key is the new wrapping key wrapped by the specified
        // wrapping key (e.g. PSK or RSA) inside a JWK. Technically we
        // shouldn't know this but that's the only way to verify things.
        //
        // Create the new wrapping key and wrap crypto context.
        final byte[] wrappingKey = new byte[16];
        pskCtx.getRandom().nextBytes(wrappingKey);
        final SecretKey wrapKey = new SecretKeySpec(wrappingKey, JcaAlgorithm.AESKW);
        final CekCryptoContext cekCryptoContext = new AesKwCryptoContext(wrapKey);
        WRAP_CRYPTO_CONTEXT = new JsonWebEncryptionCryptoContext(pskCtx, cekCryptoContext, Encryption.A128GCM,
                Format.JWE_JS);
        //
        // Wrap the new wrapping key using a PSK wrap crypto context.
        final JsonWebKey wrapJwk = new JsonWebKey(Usage.wrap, Algorithm.A128KW, false, null, wrapKey);
        WRAP_JWK = PSK_CRYPTO_CONTEXT.wrap(wrapJwk.toJSONString().getBytes(UTF_8));

        // The wrap data is an AES-128 key wrapped by the primary MSL
        // context. Technically we shouldn't know this but that's the only
        // way to verify things.
        WRAPDATA = pskCtx.getMslCryptoContext().wrap(wrappingKey);

        final WrapCryptoContextRepository repository = new MockCryptoContextRepository();
        final AuthenticationUtils authutils = new MockAuthenticationUtils();
        final KeyExchangeFactory keyxFactory = new JsonWebEncryptionLadderExchange(repository, authutils);
        pskCtx.addKeyExchangeFactory(keyxFactory);

        PSK_MASTER_TOKEN = MslTestUtils.getMasterToken(pskCtx, 1, 1);
        final SecretKey pskEncryptionKey = PSK_MASTER_TOKEN.getEncryptionKey();
        final JsonWebKey pskEncryptionJwk = new JsonWebKey(Usage.enc, Algorithm.A128CBC, false, null,
                pskEncryptionKey);
        PSK_ENCRYPTION_JWK = WRAP_CRYPTO_CONTEXT.wrap(pskEncryptionJwk.toJSONString().getBytes(UTF_8));
        final SecretKey pskHmacKey = PSK_MASTER_TOKEN.getHmacKey();
        final JsonWebKey pskHmacJwk = new JsonWebKey(Usage.sig, Algorithm.HS256, false, null, pskHmacKey);
        PSK_HMAC_JWK = WRAP_CRYPTO_CONTEXT.wrap(pskHmacJwk.toJSONString().getBytes(UTF_8));
    }
}

From source file:com.netflix.msl.keyx.JsonWebKeyLadderExchangeSuite.java

License:Open Source License

@BeforeClass
public static synchronized void setup()
        throws MslEncodingException, MslCryptoException, NoSuchAlgorithmException, MslEntityAuthException {
    if (pskCtx == null) {
        Security.addProvider(new BouncyCastleProvider());

        pskCtx = new MockMslContext(EntityAuthenticationScheme.PSK, false);

        // Create PSK wrapping crypto context.
        {/*from w w w.  j a  v a  2 s  .  co m*/
            final EntityAuthenticationData entityAuthData = pskCtx.getEntityAuthenticationData(null);
            final EntityAuthenticationFactory entityAuthFactory = pskCtx
                    .getEntityAuthenticationFactory(entityAuthData.getScheme());
            final ICryptoContext cryptoContext = entityAuthFactory.getCryptoContext(pskCtx, entityAuthData);
            PSK_CRYPTO_CONTEXT = new AesKwJwkCryptoContext(cryptoContext);
        }

        // The wrap key is the new wrapping key wrapped by the specified
        // wrapping key (e.g. PSK or RSA) inside a JWK. Technically we
        // shouldn't know this but that's the only way to verify things.
        //
        // Create the new wrapping key and wrap crypto context.
        final byte[] wrappingKey = new byte[16];
        pskCtx.getRandom().nextBytes(wrappingKey);
        final SecretKey wrapKey = new SecretKeySpec(wrappingKey, JcaAlgorithm.AESKW);
        WRAP_CRYPTO_CONTEXT = new AesKwJwkCryptoContext(wrapKey);
        //
        // Wrap the new wrapping key using a PSK wrap crypto context.
        final JsonWebKey wrapJwk = new JsonWebKey(Usage.wrap, Algorithm.A128KW, false, null, wrapKey);
        WRAP_JWK = PSK_CRYPTO_CONTEXT.wrap(wrapJwk.toJSONString().getBytes(UTF_8));

        // The wrap data is an AES-128 key wrapped by the primary MSL
        // context. Technically we shouldn't know this but that's the only
        // way to verify things.
        WRAPDATA = pskCtx.getMslCryptoContext().wrap(wrappingKey);

        final WrapCryptoContextRepository repository = new MockCryptoContextRepository();
        final AuthenticationUtils authutils = new MockAuthenticationUtils();
        final KeyExchangeFactory keyxFactory = new JsonWebKeyLadderExchange(repository, authutils);
        pskCtx.addKeyExchangeFactory(keyxFactory);

        PSK_MASTER_TOKEN = MslTestUtils.getMasterToken(pskCtx, 1, 1);
        final SecretKey pskEncryptionKey = PSK_MASTER_TOKEN.getEncryptionKey();
        final JsonWebKey pskEncryptionJwk = new JsonWebKey(Usage.enc, Algorithm.A128CBC, false, null,
                pskEncryptionKey);
        PSK_ENCRYPTION_JWK = WRAP_CRYPTO_CONTEXT.wrap(pskEncryptionJwk.toJSONString().getBytes(UTF_8));
        final SecretKey pskHmacKey = PSK_MASTER_TOKEN.getHmacKey();
        final JsonWebKey pskHmacJwk = new JsonWebKey(Usage.sig, Algorithm.HS256, false, null, pskHmacKey);
        PSK_HMAC_JWK = WRAP_CRYPTO_CONTEXT.wrap(pskHmacJwk.toJSONString().getBytes(UTF_8));
    }
}

From source file:com.nimbusds.jose.crypto.bc.BouncyCastleProviderSingleton.java

License:Apache License

/**
 * Returns a BouncyCastle JCA provider instance.
 *
 * @return The BouncyCastle JCA provider instance.
 *///from w  w w  .  j  a v a 2s .  c o m
public static BouncyCastleProvider getInstance() {

    if (bouncyCastleProvider != null) {

        return bouncyCastleProvider;

    } else {
        bouncyCastleProvider = new BouncyCastleProvider();
        return bouncyCastleProvider;
    }
}

From source file:com.nkapps.billing.services.ProviderFactoryImpl.java

@Override
public Provider getProvider() {
    if (provider != null) {
        return provider;
    }//from   w w  w . java2s.  c om
    provider = Security.getProvider("BC");
    if (provider == null) {
        BouncyCastleProvider bcp = new BouncyCastleProvider();
        // configure fake provider
        Security.addProvider(bcp);
        provider = bcp;
    }
    return provider;
}

From source file:com.oneops.cms.crypto.CmsCryptoDES.java

License:Apache License

/**
 * Inits the./*from  w  w w .j  a v  a  2  s. c o  m*/
 *
 * @throws java.io.IOException              Signals that an I/O exception has occurred.
 * @throws java.security.GeneralSecurityException the general security exception
 */
public void init() throws IOException, GeneralSecurityException {
    Security.addProvider(new BouncyCastleProvider());
    this.secretKeyFile = System.getenv("CMS_DES_PEM");
    if (this.secretKeyFile == null) {
        this.secretKeyFile = System.getProperty("com.kloopz.crypto.cms_des_pem");
    }

    if (this.secretKeyFile == null) {
        logger.error(
                ">>>>>>>>>>>>>>Failed to init DES Encryptor/Decryptor no key faile is set, use CMS_DES_PEM env var to set location!");
        throw new FileNotFoundException(
                "Failed to init DES Encryptor/Decryptor no key faile is set, use CMS_DES_PEM env var to set location!");
    }
    initEncryptorDecryptor();
}

From source file:com.oneops.cms.crypto.CmsCryptoDES.java

License:Apache License

/**
 * The main method.//w  w  w  . j  a v a  2 s  .c o m
 *
 * @param args the arguments
 */
public static void main(String[] args) {
    if (args.length < 1) {
        System.err.println("Usage: java " + CmsCryptoDES.class.getName() + " keyfile");
        System.exit(1);
    }

    System.out.println("Generate DES key file");

    Security.addProvider(new BouncyCastleProvider());
    try {
        CmsCryptoDES.generateDESKey(args[0]);
        System.out.println("DES key generated successfully.");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.oneops.cms.crypto.CmsCryptoOpenSSLImpl.java

License:Apache License

/**
 * Inits the.//from   w  w w  . jav a  2s.c  o  m
 *
 * @throws IOException Signals that an I/O exception has occurred.
 * @throws GeneralSecurityException the general security exception
 */
public void init() throws IOException, GeneralSecurityException {
    Security.addProvider(new BouncyCastleProvider());
    this.publicKeyPemFile = System.getenv("CMS_PUB_PEM");
    if (this.publicKeyPemFile == null) {
        this.publicKeyPemFile = System.getProperty("com.kloopz.crypto.cms_pub_pem");
    }
    this.privateKeyPemFile = System.getenv("CMS_PRIV_PEM");
    if (this.privateKeyPemFile == null) {
        this.privateKeyPemFile = System.getProperty("com.kloopz.crypto.cms_priv_pem");
    }

    this.passPhrase = System.getenv("CMS_PEM_PASS");
    if (this.passPhrase == null) {
        this.passPhrase = System.getProperty("com.kloopz.crypto.cms_pem_pass");
    }

    //Map<String,String> envVars = System.getenv();
    /*if (this.passPhrase == null) {
        Console cons;
        char[] passwd;
        if ((cons = System.console()) != null &&
      (passwd = cons.readPassword("[%s]", "Password:")) != null) {
     this.passPhrase = new String(passwd);
        }
    }*/

    initEncryptorDecryptor();

}

From source file:com.openbravo.pos.forms.JRootApp.java

License:Open Source License

public boolean initApp(AppProperties props, Boolean noGUI) {

    m_props = props;//w w  w.  j a v  a2 s  .  c  om
    // setPreferredSize(new java.awt.Dimension(800, 600));

    // support for different component orientation languages.
    applyComponentOrientation(ComponentOrientation.getOrientation(Locale.getDefault()));

    // Database start
    // we have three connection requests, before we say no connection
    // possible
    try {
        session = AppViewConnection.createSession(m_props);
    } catch (BasicException e) {
        if (!noGUI)
            JMessageDialog.showMessage(this, this, new MessageInf(MessageInf.SGN_DANGER, e.getMessage(), e));

        // try to close session after a invalid connection!
        if (session != null) {
            session.close();
        }

        return false;
    }

    Log.Init(session, getWindowsHost() + ": " + m_props.getHost());

    m_dlSystem = (DataLogicSystem) getBean("com.openbravo.pos.forms.DataLogicSystem");

    // Create or upgrade the database if database version is not the
    // expected
    String sDBVersion;
    Boolean bQuestionOK = false;
    do {
        sDBVersion = readDataBaseVersion();

        if (!AppLocal.APP_VERSION.equals(sDBVersion)) {

            // Create or upgrade database
            String sScript = sDBVersion.equals("create") ? m_dlSystem.getInitScript() + "-create.sql"
                    : m_dlSystem.getInitScript() + "-upgrade-" + sDBVersion + ".sql";

            /*
             * only for testing !!! String sScript =
             * sDBVersion.equals("create") ? m_dlSystem.getInitScript() +
             * "-create-2.30.2.sql" : m_dlSystem.getInitScript() +
             * "-upgrade-" + sDBVersion + ".sql";
             */

            if (JRootApp.class.getResource(sScript) == null) {
                if (!noGUI) {
                    JMessageDialog.showMessage(this, this,
                            new MessageInf(MessageInf.SGN_DANGER,
                                    sDBVersion == null
                                            ? AppLocal.getIntString("message.databasenotsupported",
                                                    session.DB.getName())
                                            : AppLocal.getIntString("message.noupdatescript")));
                }
                session.close();
                return false;
            } else {

                // Create or upgrade script exists.
                if (!noGUI && (bQuestionOK || JOptionPane.showConfirmDialog(this,
                        AppLocal.getIntString(
                                sDBVersion == null ? "message.createdatabase" : "message.updatedatabase"),
                        AppLocal.getIntString("message.title"), JOptionPane.YES_NO_OPTION,
                        JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION)) {

                    bQuestionOK = true;

                    try {
                        BatchSentence bsentence = new BatchSentenceResource(session, sScript);
                        bsentence.putParameter("APP_ID", Matcher.quoteReplacement(AppLocal.APP_ID));
                        bsentence.putParameter("APP_NAME", Matcher.quoteReplacement(AppLocal.APP_NAME));
                        bsentence.putParameter("APP_VERSION", Matcher.quoteReplacement(AppLocal.APP_VERSION));

                        java.util.List l = bsentence.list();
                        if (l.size() > 0) {
                            JMessageDialog.showMessage(this, this,
                                    new MessageInf(MessageInf.SGN_WARNING,
                                            AppLocal.getIntString("Database.ScriptWarning"),
                                            l.toArray(new Throwable[l.size()])));
                        }
                    } catch (BasicException e) {
                        JMessageDialog.showMessage(this, this, new MessageInf(MessageInf.SGN_DANGER,
                                AppLocal.getIntString("Database.ScriptError"), e));
                        session.close();
                        return false;
                    }
                } else {
                    session.close();
                    return false;
                }

            }
        }
    } while (!AppLocal.APP_VERSION.equals(sDBVersion));

    // Cargamos las propiedades de base de datos
    m_propsdb = m_dlSystem.getResourceAsProperties(m_props.getHost() + "/properties");

    // Leo la localizacion de la caja (Almacen).
    m_sInventoryLocation = m_propsdb.getProperty("location");
    if (m_sInventoryLocation == null) {
        m_sInventoryLocation = "0";
        // do not set properties
        // use default location 0
        m_propsdb.setProperty("location", m_sInventoryLocation);
        m_dlSystem.setResourceAsProperties(m_props.getHost() + "/properties", m_propsdb);
    }

    // Inicializo la impresora...
    m_TP = new DeviceTicket(this, this, m_props);

    // Inicializamos
    m_TTP = new TicketParser(getDeviceTicket(), m_dlSystem);
    printerStart();

    // Inicializamos la bascula
    m_Scale = new DeviceScale(this, this, m_props);

    // Inicializamos la scanpal
    m_Scanner = DeviceScannerFactory.createInstance(m_props);

    String sWareHouse;
    try {
        sWareHouse = m_dlSystem.findLocationName(m_sInventoryLocation);
    } catch (BasicException e) {
        sWareHouse = null; // no he encontrado el almacen principal
    }

    // Show Hostname, Warehouse and URL in taskbar
    String configName = m_props.getConfigName();
    m_jHost.setText("<html>" + m_props.getHost() + " - " + sWareHouse + " - " + configName);

    // load properties for login button size
    posprops = m_dlSystem.getResourceAsProperties("Window.Login");

    // initialise signature module
    Security.addProvider(new BouncyCastleProvider());
    try {
        SignatureModul.InitInstance(this);
        if (!noGUI) {
            SignatureModul.getInstance().CheckSignatureUnitState(this, true);

            String signatureUnitInformation = SignatureModul.getInstance().GetSignatureUnitInformation(false);
            jTextSignatureInfo.setText(signatureUnitInformation);

            showLogin();
        }
    } catch (Exception e) {
        Log.Exception(e);
        return false;
    }
    return true;
}

From source file:com.oth.jasds.crypto.Crypto.java

public Crypto() {
    Security.addProvider(new BouncyCastleProvider());
    try {//from   w  ww .  j  ava  2 s .c  o m
        // disable key strength limitation, which is set to 128bit keys by default
        Field f = Class.forName("javax.crypto.JceSecurity").getDeclaredField("isRestricted");
        f.setAccessible(true);
        f.set(null, java.lang.Boolean.FALSE);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.otterca.common.crypto.TestKeyStoreInitialization.java

License:Apache License

public TestKeyStoreInitialization() throws Exception {
    provider = new BouncyCastleProvider();
    Security.addProvider(provider);

    ks = KeyStore.getInstance("PKCS12"); // or JKS...
    ks.load(null);/* w w w . j  a  va 2 s  .com*/

    keyPairGen = KeyPairGenerator.getInstance("RSA", provider);
    keyPairGen.initialize(512);

    // policyGenerator = new SimplePolicyGeneratorImpl(
    // "http://otterca.com/cps/userdefined.txt",
    // "otterca project at google-code",
    // "This certificate is created for testing purposes only. There are no warranties of usability.",
    // Integer.valueOf(1));
}