コード例 #1
0
ファイル: Profile_.java プロジェクト: belenix/celeste
  /**
   * Verify that a given {@code Signature} was signed by this {@code Credential}.
   *
   * @param signature the signature object to verify
   * @param ids the array of object ids which the signature is purported to have signed
   * @return true if this {@code Credential} can verify that the {@code Signature} object's digital
   *     signature does correctly sign the object ids listed
   * @throws Credential.Exception
   */
  public boolean verify(Credential.Signature signature, TitanGuid... ids)
      throws Credential.Exception {

    try {
      java.security.Signature verifier =
          java.security.Signature.getInstance(signature.getAlgorithm());
      verifier.initVerify(this.publicKey);
      for (TitanGuid id : ids) {
        if (id != null) verifier.update(id.getBytes());
      }
      return verifier.verify(signature.getSignature());
    } catch (GeneralSecurityException e) {
      throw new Credential.Exception(e);
    }
  }
コード例 #2
0
ファイル: Profile_.java プロジェクト: belenix/celeste
  /**
   * Sign the collection of {@link TitanGuid} instances using this profile's private key.
   *
   * @param password the password needed access the encrypted private key
   * @param ids the list of object ids to sign
   * @return a {@code Signature} object containing the digital signature
   * @throws Credential.Exception encapsulating a {@link GeneralSecurityException} instance thrown
   *     by the underlying {@link java.security.Signature} system.
   */
  public Credential.Signature sign(char[] password, TitanGuid... ids) throws Credential.Exception {

    try {
      String algorithm = Profile_.DIGITAL_SIGNATURE_ALGORITHM;
      java.security.Signature sign = java.security.Signature.getInstance(algorithm);

      sign.initSign(this.getPrivateKey(password));
      for (TitanGuid id : ids) {
        if (id != null) sign.update(id.getBytes());
      }
      return new Credential.Signature(this.getObjectId(), sign.getAlgorithm(), sign.sign());
    } catch (GeneralSecurityException e) {
      throw new Credential.Exception(e);
    }
  }