Examples of AsymmetricBlockCipher


Examples of org.bouncycastle.crypto.AsymmetricBlockCipher

                    //
                   
                }
            }
            
            AsymmetricBlockCipher c = new PKCS1Encoding(new ElGamalEngine());

            c.init(true, pKey);
           
            byte[]  in = "hello world".getBytes();

            byte[]  out = c.processBlock(in, 0, in.length);
           
            pgpPrivKey = sKey.getSecretKey(pgpKeyID).extractPrivateKey(new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider()).build(pass));
           
            c.init(false, keyConverter.getPrivateKey(pgpPrivKey));
           
            out = c.processBlock(out, 0, out.length);
           
            if (!areEqual(in, out))
            {
                fail("decryption failed.");
            }
View Full Code Here

Examples of org.bouncycastle.crypto.AsymmetricBlockCipher

      session.disconnect("Encryption was not requested");
    } else {
      int keySize = VanillaConfiguration.ENCRYPT_KEY_SIZE.getInt();
      String keyAlgorithm = VanillaConfiguration.ENCRYPT_KEY_ALGORITHM.getString();
      String keyPadding = VanillaConfiguration.ENCRYPT_KEY_PADDING.getString();
      AsymmetricBlockCipher cipher = SecurityHandler.getInstance().getAsymmetricCipher(keyAlgorithm, keyPadding);

      AsymmetricCipherKeyPair pair = SecurityHandler.getInstance().getKeyPair(keySize, keyAlgorithm);
      cipher.init(SecurityHandler.DECRYPT_MODE, pair.getPrivate());
      final byte[] initialVector = SecurityHandler.getInstance().processAll(cipher, message.getSecretArray());

      String sessionId = session.getDataMap().get(VanillaProtocol.SESSION_ID);

      final byte[] validateToken = SecurityHandler.getInstance().processAll(cipher, message.getVerifyTokenArray());
View Full Code Here

Examples of org.bouncycastle.crypto.AsymmetricBlockCipher

      @Override
      public void run() {
        String keyAlgorithm = VanillaConfiguration.ENCRYPT_KEY_ALGORITHM.getString();
        String keyPadding = VanillaConfiguration.ENCRYPT_KEY_PADDING.getString();

        AsymmetricBlockCipher cipher = SecurityHandler.getInstance().getAsymmetricCipher(keyAlgorithm, keyPadding);

        try {
          AsymmetricKeyParameter publicKey = PublicKeyFactory.createKey(message.getSecretArray());
          cipher.init(SecurityHandler.ENCRYPT_MODE, publicKey);

          byte[] encodedSecret = cipher.processBlock(sharedSecret, 0, 16);
          byte[] encodedToken = cipher.processBlock(message.getVerifyTokenArray(), 0, 4);

          String streamCipher = VanillaConfiguration.ENCRYPT_STREAM_ALGORITHM.getString();
          String streamWrapper = VanillaConfiguration.ENCRYPT_STREAM_WRAPPER.getString();

          BufferedBlockCipher toServerCipher = SecurityHandler.getInstance().getSymmetricCipher(streamCipher, streamWrapper);
View Full Code Here

Examples of org.bouncycastle.crypto.AsymmetricBlockCipher

    // some data where first entry is 0
    byte[] data = { 10, 122, 12, 127, 35, 58, 87, 56, -6, 73, 10, -13, -78, 4, -122, -61 };

    // encrypt data asymmetrically
    AsymmetricBlockCipher cipher = new RSAEngine();
    cipher = new PKCS1Encoding(cipher);
    cipher.init(true, keyPair.getPublic());
    byte[] rsaEncryptedData = cipher.processBlock(data, 0, data.length);

    Assert.assertFalse(Arrays.equals(data, rsaEncryptedData));

    // decrypt data asymmetrically
    cipher.init(false, keyPair.getPrivate());
    byte[] dataBack = cipher.processBlock(rsaEncryptedData, 0, rsaEncryptedData.length);

    assertTrue(Arrays.equals(data, dataBack));

    long stopTime = System.currentTimeMillis();
    long elapsedTime = stopTime - startTime;
View Full Code Here

Examples of org.bouncycastle.crypto.AsymmetricBlockCipher

   */
  public static byte[] encryptCEK(final RSAPublicKey pub, final SecretKey cek)
    throws RuntimeException {

    try {
      AsymmetricBlockCipher engine = new RSAEngine();

      // JCA identifier RSA/ECB/OAEPWithSHA-1AndMGF1Padding ?
      OAEPEncoding cipher = new OAEPEncoding(engine);

      BigInteger mod = pub.getModulus();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.