LineSignatureValidator implements SignatureValidator { public byte[] generateSignature(@NonNull byte[] content) { try { final Mac mac = Mac.getInstance(HASH_ALGORITHM); mac.init(secretKeySpec); return mac.doFinal(content); } catch (NoSuchAlgorithmException | InvalidKeyException e) { throw new IllegalStateException(e); } } LineSignatureValidator(byte[] channelSecret); @Override boolean validateSignature(@NonNull byte[] content, @NonNull String headerSignature); byte[] generateSignature(@NonNull byte[] content);  }
@Test public void generateSignature() throws Exception { LineSignatureValidator lineSignatureValidator = new LineSignatureValidator( channelSecret.getBytes(StandardCharsets.UTF_8)); String httpRequestBody = "{}"; byte[] headerSignature = lineSignatureValidator .generateSignature(httpRequestBody.getBytes(StandardCharsets.UTF_8)); assertThat(Base64Utils.encodeToString(headerSignature)) .isEqualTo("3q8QXTAGaey18yL8FWTqdVlbMr6hcuNvM4tefa0o9nA="); }