Package javax.crypto

Examples of javax.crypto.Cipher$Transform


    private static byte[] getDecrypted(byte[] cyphertext, char[] password){

        try {
            /* Create PBE Cipher */
            Cipher cipher = getCipher(Cipher.DECRYPT_MODE, password);
            /* get the plaintext */
            return cipher.doFinal(cyphertext);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here


        pbeKeySpec = new PBEKeySpec(password);
        keyFac = SecretKeyFactory.getInstance(PBE_ALGORITHM);
        SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);

        /* Create PBE Cipher */
        Cipher pbeCipher = Cipher.getInstance(PBE_ALGORITHM);

        /* Initialize PBE Cipher with key and parameters */
        pbeCipher.init(mode, pbeKey, pbeParamSpec);
        return pbeCipher;
    }
View Full Code Here

        pbeKeySpec = new PBEKeySpec(PWD.toCharArray());
        keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
        SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);

        // Create PBE Cipher
        Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");

        // Initialize PBE Cipher with key and parameters
        pbeCipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec);

        // Our cleartext
        byte[] cleartext = plaintext.getBytes();

        // Encrypt the cleartext
        return pbeCipher.doFinal(cleartext);
    }
View Full Code Here

        pbeKeySpec = new PBEKeySpec(PWD.toCharArray());
        keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
        SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);

        // Create PBE Cipher
        Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");

        // Initialize PBE Cipher with key and parameters
        pbeCipher.init(Cipher.DECRYPT_MODE, pbeKey, pbeParamSpec);

        // Encrypt the cleartext
        return new String(pbeCipher.doFinal(cyphertext));
    }
View Full Code Here

    SecureRandom sr = new SecureRandom();
    byte rawKeyData[] = desKey;
    DESKeySpec dks = new DESKeySpec(rawKeyData);
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
    javax.crypto.SecretKey key = keyFactory.generateSecret(dks);
    Cipher cipher = Cipher.getInstance("DES");
    cipher.init(2, key, sr);
    byte encryptedData[] = encryptText;
    byte decryptedData[] = cipher.doFinal(encryptedData);
    return decryptedData;
  }
View Full Code Here

    SecureRandom sr = new SecureRandom();
    byte rawKeyData[] = desKey;
    DESKeySpec dks = new DESKeySpec(rawKeyData);
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
    javax.crypto.SecretKey key = keyFactory.generateSecret(dks);
    Cipher cipher = Cipher.getInstance("DES");
    cipher.init(1, key, sr);
    byte data[] = plainText;
    byte encryptedData[] = cipher.doFinal(data);
    return encryptedData;
  }
View Full Code Here

      SecretKeySpec key = new SecretKeySpec(kbytes, "Blowfish");
 
      BigInteger n = new BigInteger(secret, 16);
      byte[] encoding = n.toByteArray();
     
      Cipher cipher = Cipher.getInstance("Blowfish");
      cipher.init(Cipher.DECRYPT_MODE, key);
      byte[] decode = cipher.doFinal(encoding);
      return new String(decode);
   }
View Full Code Here

   */
  public static byte[] AESDecrypt(byte[] encrypted, byte[] key, byte[] iv) {
    try {
          SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
          IvParameterSpec ivSpec = new IvParameterSpec(iv);
          Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
          cipher.init(Cipher.DECRYPT_MODE, skeySpec, ivSpec);
          return cipher.doFinal(encrypted);
    } catch(InvalidKeyException e) {
      throw new IllegalArgumentException(
          "if you see 'java.security.InvalidKeyException: Illegal key size', it cause by default JCE does not support 256-aes key for shipping reason.\n" +
          "but you can download those two policy files" +
          "    (US_export_policy.jar,local_policy.jar : Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files) " +
View Full Code Here

     * @return byte[] 加密后的字节数组
     */
    protected byte[] encrypt(RSAPublicKey publicKey, byte[] obj) {
        if (publicKey != null) {
            try {
                Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
                cipher.init(Cipher.ENCRYPT_MODE, publicKey);
                return cipher.doFinal(obj);
            } catch (Exception e){
                e.printStackTrace();
            }
        }
        return null;
View Full Code Here

     * @return byte[]
     */
    protected byte[] decrypt(RSAPrivateKey privateKey, byte[] obj) {
        if (privateKey != null) {
                try{
                    Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");

                    cipher.init(Cipher.DECRYPT_MODE, privateKey);
                    return cipher.doFinal(obj);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
   
View Full Code Here

TOP

Related Classes of javax.crypto.Cipher$Transform

Copyright © 2018 www.massapicom. 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.