Beispiel #1
0
 @Override
 public TitanGuid getDataId() {
   if (this.dataId == null) {
     //
     // Hash together everything that distinguishes this profile from any
     // other object stored in Beehive.  (Since the cachedId field is
     // derived from the name field, it's not included.)
     //
     TitanGuid id = new TitanGuidImpl(this.name.getBytes());
     id = id.add(this.encryptedPrivateKey);
     this.dataId = id.add(this.publicKey.getEncoded());
   }
   return this.dataId;
 }
Beispiel #2
0
  /**
   * 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);
    }
  }
Beispiel #3
0
  /**
   * 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);
    }
  }