コード例 #1
0
  PKCS12PBECipherCore(String symmCipherAlg, int defKeySize) throws NoSuchAlgorithmException {

    algo = symmCipherAlg;
    if (algo.equals("RC4")) {
      pbeAlgo = "PBEWithSHA1AndRC4_" + defKeySize * 8;
    } else {
      SymmetricCipher symmCipher = null;
      if (algo.equals("DESede")) {
        symmCipher = new DESedeCrypt();
        pbeAlgo = "PBEWithSHA1AndDESede";
      } else if (algo.equals("RC2")) {
        symmCipher = new RC2Crypt();
        pbeAlgo = "PBEWithSHA1AndRC2_" + defKeySize * 8;
      } else {
        throw new NoSuchAlgorithmException(
            "No Cipher implementation " + "for PBEWithSHA1And" + algo);
      }
      blockSize = symmCipher.getBlockSize();
      cipher = new CipherCore(symmCipher, blockSize);
      cipher.setMode("CBC");
      try {
        cipher.setPadding("PKCS5Padding");
      } catch (NoSuchPaddingException nspe) {
        // should not happen
      }
    }
    keySize = defKeySize;
  }
コード例 #2
0
 /**
  * Sets the mode of this cipher.
  *
  * @param mode the cipher mode
  * @exception NoSuchAlgorithmException if the requested cipher mode does not exist
  */
 protected void engineSetMode(String mode) throws NoSuchAlgorithmException {
   core.setMode(mode);
 }