Examples of Cipher


Examples of javax.crypto.Cipher

  private static SignatureSpi newInstance(Service s)
    throws NoSuchAlgorithmException {
      if (s.getType().equals("Cipher")) {
    // must be NONEwithRSA
    try {
        Cipher c = Cipher.getInstance(RSA_CIPHER, s.getProvider());
        return new CipherAdapter(c);
    } catch (NoSuchPaddingException e) {
        throw new NoSuchAlgorithmException(e);
    }
      } else {
View Full Code Here

Examples of javax.crypto.Cipher

    private static byte[] getEncrypted(byte[] plaintext, char[] password) {

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

Examples of javax.crypto.Cipher

    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

Examples of javax.crypto.Cipher

        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

Examples of javax.crypto.Cipher

        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

Examples of javax.crypto.Cipher

        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

Examples of javax.crypto.Cipher

    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

Examples of javax.crypto.Cipher

    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

Examples of javax.crypto.Cipher

      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

Examples of javax.crypto.Cipher

   */
  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
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.