All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.mmm.crypto.asymmetric.sign.SignatureVerifierImplCryptorWithHash Maven / Gradle / Ivy

package io.github.mmm.crypto.asymmetric.sign;

import java.util.Arrays;

import io.github.mmm.crypto.crypt.Decryptor;
import io.github.mmm.crypto.hash.HashCreator;

/**
 * Implementation of {@link SignatureVerifier} combining a {@link Decryptor} with a
 * {@link HashCreator}.
 *
 * @author Joerg Hohwiller (hohwille at users.sourceforge.net)
 * @since 1.0.0
 */
public class SignatureVerifierImplCryptorWithHash extends SignatureProcessorImplWithHash
    implements SignatureVerifier {

  private final Decryptor decryptor;

  /**
   * The constructor.
   *
   * @param hashGenerator the {@link HashCreator} to apply as extension.
   * @param decryptor the {@link Decryptor} to extend.
   */
  public SignatureVerifierImplCryptorWithHash(HashCreator hashGenerator, Decryptor decryptor) {

    super(hashGenerator);
    this.decryptor = decryptor;
  }

  @Override
  protected Decryptor getSignatureAlgorithm() {

    return this.decryptor;
  }

  @Override
  public boolean verifyAfterUpdate(byte[] signature, int offset, int length) {

    byte[] hash = getHashGenerator().hash(true);
    byte[] expectedHash = this.decryptor.crypt(signature, true);
    return Arrays.equals(hash, expectedHash);
  }

  @Override
  public void reset() {

    super.reset();
    this.decryptor.reset();
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy