Examples of Cipher


Examples of javax.crypto.Cipher

     
      String plainText = "";
     
     
      while(blocks.hasMoreTokens()) {
        Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
       
        cipher.init(Cipher.DECRYPT_MODE, pk.getPrivateKey());
       
        byte[] encrypted = Base64.decode(blocks.nextToken());
        byte[] ctext = cipher.doFinal(encrypted);
       
        plainText += new String(ctext);
      }
     
     
View Full Code Here

Examples of javax.crypto.Cipher

            Security.addProvider(bp);

            //Cipher encrypt = Cipher.getInstance("DES");           
            //SecretKey key = new SecretKeySpec(pass.getBytes(), "DES");
           
            Cipher encrypt = Cipher.getInstance("DESede/ECB/NoPadding", "BC");

            SecretKey key = new SecretKeySpec(pass.getBytes(), "DESede");

            encrypt.init(Cipher.ENCRYPT_MODE, key);

            // encode string mit utf8           
            byte[] utf8 = str.getBytes(SOSCrypt.charset);

            // encrypt
            byte[] enc = encrypt.doFinal(utf8);

            // encode bytes zu base64
            return new sun.misc.BASE64Encoder().encode(enc);

        } catch (Exception e) {         
View Full Code Here

Examples of javax.crypto.Cipher

            Security.addProvider(bp);


            //Cipher decrypt = Cipher.getInstance("DES");
            //SecretKey key = new SecretKeySpec(pass.getBytes(), "DES");
            Cipher decrypt = Cipher.getInstance("DESede/ECB/NoPadding", "BC");

            SecretKey key = new SecretKeySpec(pass.getBytes(), "DESede");

            decrypt.init(Cipher.DECRYPT_MODE, key);


            // decode base64 zu bytes                               
            byte[] dec = new sun.misc.BASE64Decoder().decodeBuffer(str);

            // decrypt
            byte[] utf8 = decrypt.doFinal(dec);//->javax.crypto.IllegalBlockSizeException: data not block size aligned

            // decode mit utf-8
            return new String(utf8, SOSCrypt.charset).trim();

        } catch (Exception e) {         
View Full Code Here

Examples of net.schmizz.sshj.transport.cipher.Cipher

        // Ref. https://issues.apache.org/jira/browse/SSHD-24
        // "AES256 and AES192 requires unlimited cryptography extension"
        for (Iterator<Factory.Named<Cipher>> i = avail.iterator(); i.hasNext(); ) {
            final Factory.Named<Cipher> f = i.next();
            try {
                final Cipher c = f.create();
                final byte[] key = new byte[c.getBlockSize()];
                final byte[] iv = new byte[c.getIVSize()];
                c.init(Cipher.Mode.Encrypt, key, iv);
            } catch (Exception e) {
                warn = true;
                i.remove();
            }
        }
View Full Code Here

Examples of org.apache.hadoop.hbase.io.crypto.Cipher

    }

    // Crypto context for new store files
    String cipherName = family.getEncryptionType();
    if (cipherName != null) {
      Cipher cipher;
      Key key;
      byte[] keyBytes = family.getEncryptionKey();
      if (keyBytes != null) {
        // Family provides specific key material
        String masterKeyName = conf.get(HConstants.CRYPTO_MASTERKEY_NAME_CONF_KEY,
          User.getCurrent().getShortName());
        try {
          // First try the master key
          key = EncryptionUtil.unwrapKey(conf, masterKeyName, keyBytes);
        } catch (KeyException e) {
          // If the current master key fails to unwrap, try the alternate, if
          // one is configured
          if (LOG.isDebugEnabled()) {
            LOG.debug("Unable to unwrap key with current master key '" + masterKeyName + "'");
          }
          String alternateKeyName =
            conf.get(HConstants.CRYPTO_MASTERKEY_ALTERNATE_NAME_CONF_KEY);
          if (alternateKeyName != null) {
            try {
              key = EncryptionUtil.unwrapKey(conf, alternateKeyName, keyBytes);
            } catch (KeyException ex) {
              throw new IOException(ex);
            }
          } else {
            throw new IOException(e);
          }
        }
        // Use the algorithm the key wants
        cipher = Encryption.getCipher(conf, key.getAlgorithm());
        if (cipher == null) {
          throw new RuntimeException("Cipher '" + cipher + "' is not available");
        }
        // Fail if misconfigured
        // We use the encryption type specified in the column schema as a sanity check on
        // what the wrapped key is telling us
        if (!cipher.getName().equalsIgnoreCase(cipherName)) {
          throw new RuntimeException("Encryption for family '" + family.getNameAsString() +
            "' configured with type '" + cipherName +
            "' but key specifies algorithm '" + cipher.getName() + "'");
        }
      } else {
        // Family does not provide key material, create a random key
        cipher = Encryption.getCipher(conf, cipherName);
        if (cipher == null) {
          throw new RuntimeException("Cipher '" + cipher + "' is not available");
        }
        key = cipher.getRandomKey();
      }
      cryptoContext = Encryption.newContext(conf);
      cryptoContext.setCipher(cipher);
      cryptoContext.setKey(key);
    }
View Full Code Here

Examples of org.apache.sshd.common.Cipher

        avail.add(new AES256CBC.Factory());

        for (Iterator<NamedFactory<Cipher>> i = avail.iterator(); i.hasNext();) {
            final NamedFactory<Cipher> f = i.next();
            try {
                final Cipher c = f.create();
                final byte[] key = new byte[c.getBlockSize()];
                final byte[] iv = new byte[c.getIVSize()];
                c.init(Cipher.Mode.Encrypt, key, iv);
            } catch (InvalidKeyException e) {
                i.remove();
            } catch (Exception e) {
                i.remove();
            }
View Full Code Here

Examples of org.slim3.util.Cipher

     *            the text
     * @return the encrypted text
     * @since 1.0.6
     */
    protected String encrypt(String text) {
        Cipher c = CipherFactory.getFactory().createCipher();
        return c.encrypt(text);
    }
View Full Code Here

Examples of tools.elgamal.Cipher

    }
    Object key = ChatterContext.get(getCk().getB(),
        PublicKeyRequest.PUBLIC_KEY);
    ChatterContext.put(getCk().getB(), SHARED_KEY, plainKey);
    try {
      Cipher elgamal = new ElgamalCipher();
      elgamal.init(Cipher.ENCRYPT_MODE, key);
      elgamal.update(plainKey);
      this.encryptedKey = elgamal.doFinal();
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
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.