AbstractPostFinancePaymentGatewayImpl implements ConfigurablePaymentGateway, PaymentGateway { protected String sha1sign(final Map<String, String> params, final String secret) { final StringBuilder all = new StringBuilder(); for (final Map.Entry<String, String> entry : params.entrySet()) { if (StringUtils.isNotBlank(entry.getValue())) { all.append(entry.getKey().toUpperCase()).append("=").append(entry.getValue()).append(secret); } } try { final Charset charset = StandardCharsets.UTF_8; final MessageDigest digest = MessageDigest.getInstance("SHA-1"); return new String(Hex.encodeHex(digest.digest(all.toString().getBytes(charset)))).toUpperCase(); } catch (NoSuchAlgorithmException e) { LOG.error("SHA-1 not available: " + e.getMessage(), e); return "SHA-1 not available"; } }  @Override String getShopCode(); @Override String getLabel(); @Override String getName(final String locale); @Override Collection<PaymentGatewayParameter> getPaymentGatewayParameters(); @Override void deleteParameter(final String parameterLabel); @Override void addParameter(final PaymentGatewayParameter paymentGatewayParameter); @Override void updateParameter(final PaymentGatewayParameter paymentGatewayParameter); void setPaymentGatewayParameterService(
            final PaymentGatewayParameterService paymentGatewayParameterService); @Override String getParameterValue(final String valueLabel); static String dump(Map<?, ?> map); @Override void accept(final PaymentGatewayConfigurationVisitor visitor);  }
@Test public void testSha1() throws Exception { final AbstractPostFinancePaymentGatewayImpl pg = new AbstractPostFinancePaymentGatewayImpl() { @Override public Payment authorizeCapture(final Payment payment, final boolean forceProcessing) { return null; } @Override public Payment authorize(final Payment payment, final boolean forceProcessing) { return null; } @Override public Payment reverseAuthorization(final Payment payment, final boolean forceProcessing) { return null; } @Override public Payment capture(final Payment payment, final boolean forceProcessing) { return null; } @Override public Payment voidCapture(final Payment payment, final boolean forceProcessing) { return null; } @Override public Payment refund(final Payment payment, final boolean forceProcessing) { return null; } @Override public PaymentGatewayFeature getPaymentGatewayFeatures() { return null; } @Override public Collection<PaymentGatewayParameter> getPaymentGatewayParameters() { return null; } @Override public String getHtmlForm(final String cardHolderName, final String locale, final BigDecimal amount, final String currencyCode, final String orderReference, final Payment payment) { return null; } @Override public Payment createPaymentPrototype(final String operation, final Map map, final boolean forceProcessing) { return null; } }; final Map<String, String> params1 = new LinkedHashMap<>(); params1.put("P1", "123"); params1.put("P2", "345"); final Map<String, String> params2 = new LinkedHashMap<>(); params2.put("P1", "123"); params2.put("P2", "345"); final String sha1_1 = pg.sha1sign(params1, "secret1"); assertNotNull(sha1_1); final String sha1_2 = pg.sha1sign(params1, "secret2"); assertNotNull(sha1_2); assertFalse(sha1_1.equals(sha1_2)); final String sha1_3 = pg.sha1sign(params1, "secret1"); assertNotNull(sha1_3); final String sha1_4 = pg.sha1sign(params2, "secret1"); assertNotNull(sha1_4); assertEquals(sha1_3, sha1_4); final Map<String, String> params3 = new LinkedHashMap<>(); params3.put("AMOUNT", "1500"); params3.put("CURRENCY", "EUR"); params3.put("LANGUAGE", "en_US"); params3.put("ORDERID", "1234"); params3.put("PSPID", "MyPSPID"); final String sha1_5 = pg.sha1sign(params3, "Mysecretsig1875!?"); assertEquals("F4CC376CD7A834D997B91598FA747825A238BE0A", sha1_5); }