Пример #1
0
 /**
  * Initializes this cipher with a key and a source of randomness. The cipher is initialized for
  * one of the following four operations: encryption, decryption, key wrapping or key unwrapping,
  * depending on the value of <code>opmode</code>.
  *
  * <p>If this cipher (including its underlying feedback or padding scheme) requires any random
  * bytes, it will get them from <code>random</code>.
  *
  * @param opmode the operation mode of this cipher (this is one of the following: <code>
  *     ENCRYPT_MODE</code>, <code>DECRYPT_MODE</code>), <code>WRAP_MODE</code> or <code>
  *     UNWRAP_MODE</code>)
  * @param key the encryption key
  * @param random the source of randomness
  * @exception InvalidKeyException if the given key is inappropriate for initializing this cipher
  */
 protected void engineInit(int opmode, Key key, SecureRandom random) throws InvalidKeyException {
   try {
     core.init(opmode, key, (AlgorithmParameterSpec) null, random);
   } catch (InvalidAlgorithmParameterException ie) {
     InvalidKeyException ike = new InvalidKeyException("requires PBE parameters");
     ike.initCause(ie);
     throw ike;
   }
 }
  public Boolean verifySignature(byte[] originalData, byte[] signedData) {
    boolean verified = false;

    try {
      Signature sig = Signature.getInstance("SHA1withDSA", "SUN");
      sig.initVerify(getPublicKey());
      sig.update(originalData, 0, originalData.length);
      verified = sig.verify(signedData);
    } catch (SignatureException ex) {
      ex.printStackTrace();
      Logger.getLogger(SignatureVerifier.class.getName()).log(Level.SEVERE, null);
    } catch (InvalidKeyException ex) {
      ex.printStackTrace();
      Logger.getLogger(SignatureVerifier.class.getName()).log(Level.SEVERE, null);
    } catch (NoSuchAlgorithmException ex) {
      ex.printStackTrace();
      Logger.getLogger(SignatureVerifier.class.getName()).log(Level.SEVERE, null);
    } catch (NoSuchProviderException ex) {
      ex.printStackTrace();
      Logger.getLogger(SignatureVerifier.class.getName()).log(Level.SEVERE, null);
    }

    return verified;
  }