コード例 #1
0
  /**
   * Method init
   *
   * @param forWrapping
   * @param param
   */
  public void init(boolean forWrapping, CipherParameters param) {

    this.forWrapping = forWrapping;
    this.engine = new CBCBlockCipher(new DESedeEngine());

    SecureRandom sr;
    if (param instanceof ParametersWithRandom) {
      ParametersWithRandom pr = (ParametersWithRandom) param;
      param = pr.getParameters();
      sr = pr.getRandom();
    } else {
      sr = new SecureRandom();
    }

    if (param instanceof KeyParameter) {
      this.param = (KeyParameter) param;

      if (this.forWrapping) {

        // Hm, we have no IV but we want to wrap ?!?
        // well, then we have to create our own IV.
        this.iv = new byte[8];
        sr.nextBytes(iv);

        this.paramPlusIV = new ParametersWithIV(this.param, this.iv);
      }
    } else if (param instanceof ParametersWithIV) {
      this.paramPlusIV = (ParametersWithIV) param;
      this.iv = this.paramPlusIV.getIV();
      this.param = (KeyParameter) this.paramPlusIV.getParameters();

      if (this.forWrapping) {
        if ((this.iv == null) || (this.iv.length != 8)) {
          throw new IllegalArgumentException("IV is not 8 octets");
        }
      } else {
        throw new IllegalArgumentException("You should not supply an IV for unwrapping");
      }
    }
  }
コード例 #2
0
ファイル: GMSSSigner.java プロジェクト: javabeanz/basecrypto
  public void init(boolean forSigning, CipherParameters param) {

    if (forSigning) {
      if (param instanceof ParametersWithRandom) {
        ParametersWithRandom rParam = (ParametersWithRandom) param;

        // XXX random needed?
        this.random = rParam.getRandom();
        this.key = (GMSSPrivateKeyParameters) rParam.getParameters();
        initSign();

      } else {

        this.random = new SecureRandom();
        this.key = (GMSSPrivateKeyParameters) param;
        initSign();
      }
    } else {
      this.key = (GMSSPublicKeyParameters) param;
      initVerify();
    }
  }