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:core.RSA.java

public RSA() throws NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException {
    Security.addProvider(new BouncyCastleProvider());

    Cipher cipher = Cipher.getInstance("RSA/None/NoPadding", "BC");
    SecureRandom random = new SecureRandom();
    KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA", "BC");

    generator.initialize(256, random);//  ww w.  j a va  2  s. co  m
    keyPair = generator.generateKeyPair();

}

From source file:COSE.OneKeyTest.java

/**
 * Test of AsPublicKey method, of class OneKey.
 *//*w w w.ja v a  2  s  .  co  m*/
@Test
public void testAsPublicKey() throws Exception {
    OneKey instance = OneKey.generateKey(AlgorithmID.ECDSA_256);
    PublicKey result = instance.AsPublicKey();
    assertEquals(result.getAlgorithm(), "EC");
    assertEquals(result.getFormat(), "X.509");

    byte[] rgbSPKI = result.getEncoded();
    String f = byteArrayToHex(rgbSPKI);
    assertEquals(rgbSPKI.length, 91);

    KeyFactory kFactory = KeyFactory.getInstance("EC", new BouncyCastleProvider());
    X509EncodedKeySpec spec = new X509EncodedKeySpec(rgbSPKI);
    PublicKey pubKey = (PublicKey) kFactory.generatePublic(spec);
}

From source file:COSE.OneKeyTest.java

/**
 * Test of AsPrivateKey method, of class OneKey.
 *//* w  ww. jav a  2 s . co m*/
@Test
public void testAsPrivateKey() throws Exception {
    OneKey instance = OneKey.generateKey(AlgorithmID.ECDSA_256);
    PrivateKey result = instance.AsPrivateKey();

    assertEquals(result.getAlgorithm(), "EC");
    assertEquals(result.getFormat(), "PKCS#8");

    byte[] rgbPrivate = result.getEncoded();
    String x = byteArrayToHex(rgbPrivate);

    /*
            
    THis seems to go boom on jdk 9
    KeyPairGenerator kpgen = KeyPairGenerator.getInstance("EC");
            
    */

    KeyFactory kFactory = KeyFactory.getInstance("EC", new BouncyCastleProvider());

    PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(rgbPrivate);
    PrivateKey pubKey = (PrivateKey) kFactory.generatePrivate(spec);
}

From source file:cosis.Main.java

License:Open Source License

public static void main(String[] args) {

    if (GraphicsEnvironment.isHeadless()) {
        System.out.println("\nSorry, Cosis is not command-line friendly,"
                + "\nalthough it wouldn't be hard to make a CLI interface...\n"
                + "send me an email if you want one: " + CONTACT + "\n");
        System.exit(0);//from  www  .  j a  v  a 2  s. c  om
    }

    //Check the OS and Java Version. Version >= 1.6 && OS != Macintosh
    String osName = System.getProperty("os.name");
    if (osName.startsWith("Windows")) {
        WIN = true;
    } else if (osName.startsWith("Mac")) {
        MAC = true;
    } else {
        UNIX = true;
    }

    try {
        double javaVersion = Double.parseDouble(System.getProperty("java.specification.version"));
        if (javaVersion < 1.5) {
            JOptionPane.showMessageDialog(null,
                    "Your system has an outdated version of the Java" + " Runtime Environment (" + javaVersion
                            + ").\n" + "Please update your version.",
                    "Outdated Java - " + Main.NAME, JOptionPane.INFORMATION_MESSAGE);
            System.exit(0);
        }
    } catch (NumberFormatException x) {
        System.err.println("COSIS - VERSION CHECKING FAILED");
        x.printStackTrace();
        System.exit(1);
    }

    /**
     * From here on, we're on a normal OS with a proper version of Java.
     */
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception x) {
        System.err.println("COSIS - NATIVE SYSTEM THEME SET FAILED");
        x.printStackTrace();
        System.exit(1);
    }

    TRAY = SystemTray.isSupported();
    FIRST_RUN = FileIO.isFirstRun();
    Security.addProvider(new BouncyCastleProvider());
    wm = new WindowManager();
    //Start the GUI
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            if (FIRST_RUN) {
                wm.setMajorWindow(new Welcome());
            } else {
                wm.setMajorWindow(new SignIn());
            }
        }
    });
}

From source file:craterdog.security.RsaAesMessageCryptex.java

License:Open Source License

/**
 * This default constructor creates the cryptex and initializes the security provider.
 */// ww w . j  a  v a  2 s. c o  m
public RsaAesMessageCryptex() {
    logger.entry();
    Security.addProvider(new BouncyCastleProvider());
    logger.exit();
}

From source file:craterdog.security.RsaCertificateManager.java

License:Open Source License

/**
 * This default constructor sets up the security implementation provider.
 *///from w ww  . j a v a  2 s.  c o m
public RsaCertificateManager() {
    logger.entry();
    logger.debug("Adding the security implementation provider...");
    Security.addProvider(new BouncyCastleProvider());
    logger.exit();
}

From source file:cryptcod.helpers.AES.java

/**
 * @param args//ww  w  . ja  v a  2  s  . com
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    Security.addProvider(new BouncyCastleProvider());

    String password = "TESTPASS";
    String salt = "1234";

    /* Derive the key, given password and salt. */
    SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
    KeySpec spec = new PBEKeySpec(password.toCharArray(), salt.getBytes(), 65536, 256);
    SecretKey tmp = factory.generateSecret(spec);
    SecretKey secret = new SecretKeySpec(tmp.getEncoded(), ALGORITHM);

    /* Encrypt the message. */

    //GCMParameterSpec test = new GCMParameterSpec();

    Cipher cipher = Cipher.getInstance(ALGORITHM + "/" + MODE + "/" + PADDING, "BC");
    cipher.init(Cipher.ENCRYPT_MODE, secret);
    AlgorithmParameters params = cipher.getParameters();
    byte[] iv = params.getParameterSpec(IvParameterSpec.class).getIV();
    System.out.println("IV length: " + iv.length * 8);
    byte[] ciphertext = cipher.doFinal(TESTTEXT.getBytes(ENCODING));
    System.out.println(new String(ciphertext, ENCODING));
    System.out.println(ciphertext.length);
    ciphertext[45] = 6;

    /* Decrypt the message, given derived key and initialization vector. */
    Cipher cipher2 = Cipher.getInstance(ALGORITHM + "/" + MODE + "/" + PADDING, "BC");
    cipher2.init(Cipher.DECRYPT_MODE, secret, new IvParameterSpec(iv));
    String plaintext = new String(cipher2.doFinal(ciphertext), ENCODING);
    System.out.println(plaintext);
}

From source file:Crypto.ChiffreDES.java

@Override
public void init(Cle k) {
    Security.addProvider(new BouncyCastleProvider());
    this.Cle = (CleDES) k;
}

From source file:Crypto.ChiffreDES.java

@Override
public String crypte(String plainTextObj) // passer un String et return des bytes
{
    Security.addProvider(new BouncyCastleProvider());
    String plainText = (String) plainTextObj;
    String textCr = null;/*from w  w w  .  j a v  a 2s.  c  o  m*/
    byte[] texteCrypte = null;
    byte[] encodedBytes = null;
    try {
        Cipher chiffrement = Cipher.getInstance("DES/ECB/PKCS5Padding", "BC");
        chiffrement.init(Cipher.ENCRYPT_MODE, this.Cle.getSecretKey());
        byte[] texteClair = plainText.getBytes();
        byte[] ciphertext = chiffrement.doFinal(texteClair);
        encodedBytes = Base64.encodeBase64(ciphertext);
        System.out.println("EncodedBytes" + new String(encodedBytes));
    } catch (IllegalBlockSizeException ex) {
        Logger.getLogger(ChiffreDES.class.getName()).log(Level.SEVERE, null, ex);
    } catch (BadPaddingException ex) {
        Logger.getLogger(ChiffreDES.class.getName()).log(Level.SEVERE, null, ex);
    } catch (NoSuchAlgorithmException ex) {
        Logger.getLogger(ChiffreDES.class.getName()).log(Level.SEVERE, null, ex);
    } catch (NoSuchProviderException ex) {
        Logger.getLogger(ChiffreDES.class.getName()).log(Level.SEVERE, null, ex);
    } catch (NoSuchPaddingException ex) {
        Logger.getLogger(ChiffreDES.class.getName()).log(Level.SEVERE, null, ex);
    } catch (InvalidKeyException ex) {
        Logger.getLogger(ChiffreDES.class.getName()).log(Level.SEVERE, null, ex);
    }

    return new String(encodedBytes);
}

From source file:crypto.performance.Libraries.java

License:Open Source License

/**
 * Register all libraries before testing.
 *
 * @since 1.0/*w  ww. j  av a  2  s .  c  o  m*/
 */
public static void registerProviders() {
    Security.addProvider(new BouncyCastleProvider());
    Security.addProvider(new FlexiCoreProvider());
    Security.addProvider(new FlexiECProvider());
    System.out.println("Providers:");
    System.out.println(Arrays.toString(Security.getProviders()));
}