public void afterPropertiesSet() throws Exception {
    // Check the signing and verification keys match
    if (signer instanceof RsaSigner) {
      RsaVerifier verifier;
      try {
        verifier = new RsaVerifier(verifierKey);
      } catch (Exception e) {
        logger.warn("Unable to create an RSA verifier from verifierKey");
        return;
      }

      byte[] test = "test".getBytes();
      try {
        verifier.verify(test, signer.sign(test));
        logger.info("Signing and verification RSA keys match");
      } catch (InvalidSignatureException e) {
        logger.error("Signing and verification RSA keys do not match");
      }
    } else {
      // Avoid a race condition where setters are called in the wrong order. Use of == is
      // intentional.
      Assert.state(
          this.signingKey == this.verifierKey,
          "For MAC signing you do not need to specify the verifier key separately, and if you do it must match the signing key");
    }
    SignatureVerifier verifier = new MacSigner(verifierKey);
    try {
      verifier = new RsaVerifier(verifierKey);
    } catch (Exception e) {
      logger.warn("Unable to create an RSA verifier from verifierKey");
    }
    this.verifier = verifier;
  }
예제 #2
0
  @Override
  public void afterPropertiesSet() throws Exception {
    // Check the signing and verification keys match
    if (signer instanceof RsaSigner) {
      RsaVerifier verifier;
      try {
        verifier = new RsaVerifier(verifierKey);
      } catch (Exception e) {
        logger.warn("Unable to create an RSA verifier from verifierKey");
        return;
      }

      byte[] test = "test".getBytes();
      try {
        verifier.verify(test, signer.sign(test));
        logger.info("Signing and verification RSA keys match");
      } catch (InvalidSignatureException e) {
        logger.error("Signing and verification RSA keys do not match");
      }
    } else {
      // Avoid a race condition where verifier is set after signer to a different (possibly
      // incompatible value)
      Assert.state(
          this.signingKey == this.verifierKey,
          "For MAC signing you do not need to specify the verifier key separately, and if you do it must match the signing key");
    }
  }