Example #1
0
  /**
   * initialise a RC5-64 cipher.
   *
   * @param forEncryption whether or not we are for encryption.
   * @param params the parameters required to set up the cipher.
   * @exception IllegalArgumentException if the params argument is inappropriate.
   */
  public void init(boolean forEncryption, CipherParameters params) {
    if (!(params instanceof RC5Parameters)) {
      throw new IllegalArgumentException(
          "invalid parameter passed to RC564 init - " + params.getClass().getName());
    }

    RC5Parameters p = (RC5Parameters) params;

    this.forEncryption = forEncryption;

    _noRounds = p.getRounds();

    setKey(p.getKey());
  }
Example #2
0
  /**
   * initialise a RC4 cipher.
   *
   * @param forEncryption whether or not we are for encryption.
   * @param params the parameters required to set up the cipher.
   * @exception IllegalArgumentException if the params argument is inappropriate.
   */
  public void init(boolean forEncryption, CipherParameters params) {
    if (params instanceof KeyParameter) {
      /*
       * RC4 encryption and decryption is completely
       * symmetrical, so the 'forEncryption' is
       * irrelevant.
       */
      workingKey = ((KeyParameter) params).getKey();
      setKey(workingKey);

      return;
    }

    throw new IllegalArgumentException(
        "invalid parameter passed to RC4 init - " + params.getClass().getName());
  }