Пример #1
0
 AlgorithmParameters implGetParameters() {
   AlgorithmParameters params = null;
   if (salt == null) {
     // Cipher is not initialized with parameters;
     // follow the recommendation in PKCS12 v1.0
     // section B.4 to generate salt and iCount.
     salt = new byte[DEFAULT_SALT_LENGTH];
     SunJCE.getRandom().nextBytes(salt);
     iCount = DEFAULT_COUNT;
   }
   PBEParameterSpec pbeSpec = new PBEParameterSpec(salt, iCount);
   try {
     params = AlgorithmParameters.getInstance(pbeAlgo, "SunJCE");
   } catch (GeneralSecurityException gse) {
     // should never happen
     throw new RuntimeException("SunJCE provider is not configured properly");
   }
   try {
     params.init(pbeSpec);
   } catch (InvalidParameterSpecException ipse) {
     // should never happen
     throw new RuntimeException("PBEParameterSpec not supported");
   }
   return params;
 }
Пример #2
0
  /*
   * Generate PBE Algorithm Parameters
   */
  private AlgorithmParameters getAlgorithmParameters(String algorithm) throws IOException {
    AlgorithmParameters algParams = null;

    // create PBE parameters from salt and iteration count
    PBEParameterSpec paramSpec = new PBEParameterSpec(getSalt(), iterationCount);
    try {
      algParams = AlgorithmParameters.getInstance(algorithm);
      algParams.init(paramSpec);
    } catch (Exception e) {
      IOException ioe = new IOException("getAlgorithmParameters failed: " + e.getMessage());
      ioe.initCause(e);
      throw ioe;
    }
    return algParams;
  }
  private AlgorithmParameters getParameters() throws NoSuchAlgorithmException {
    AlgorithmParameters ap = AlgorithmParameters.getInstance(this.getAlgName());
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    DEROutputStream dOut = new DEROutputStream(bOut);

    try {
      dOut.writeObject(infoObj.getEncryptionAlgorithm().getParameters());
      dOut.close();

      ap.init(bOut.toByteArray());
    } catch (IOException e) {
      throw new NoSuchAlgorithmException("unable to parse parameters");
    }

    return ap;
  }
Пример #4
0
 // see JCE spec
 protected AlgorithmParameters engineGetParameters() {
   if (iv == null) {
     return null;
   }
   IvParameterSpec ivSpec = new IvParameterSpec(iv);
   try {
     AlgorithmParameters params =
         AlgorithmParameters.getInstance(keyAlgorithm, P11Util.getSunJceProvider());
     params.init(ivSpec);
     return params;
   } catch (GeneralSecurityException e) {
     // NoSuchAlgorithmException, NoSuchProviderException
     // InvalidParameterSpecException
     throw new ProviderException("Could not encode parameters", e);
   }
 }
Пример #5
0
 /*
  * parse Algorithm Parameters
  */
 private AlgorithmParameters parseAlgParameters(DerInputStream in) throws IOException {
   AlgorithmParameters algParams = null;
   try {
     DerValue params;
     if (in.available() == 0) {
       params = null;
     } else {
       params = in.getDerValue();
       if (params.tag == DerValue.tag_Null) {
         params = null;
       }
     }
     if (params != null) {
       algParams = AlgorithmParameters.getInstance("PBE");
       algParams.init(params.toByteArray());
     }
   } catch (Exception e) {
     IOException ioe = new IOException("parseAlgParameters failed: " + e.getMessage());
     ioe.initCause(e);
     throw ioe;
   }
   return algParams;
 }