@Test public void testWithRealSignature() { RequestSigner requestSigner = new RequestSigner(getBytes("Wb3N9gKeFf8ZoCzlOb5lJSic7bHLUcSu")); String requestSignature = "5Jha9Yyhwgc1nTsgJ9WyzeHilsuUumydICdf4LuIZE8="; String requestTimestamp = "1547036603"; String requestParams = "id=57db52e04e2f4001b555f79813a0f503&mccmnc=20409&ported=0&recipient=31667788880&reference=curl&status=delivered&statusDatetime=2019-01-09T12%3A23%3A23%2B00%3A00"; byte[] requestBody = new byte[0]; String spoiledSignature = "5Jha9Yyhwgc1nTsgJ9WyzeHilsuUumydICdf4LUIZE8="; String spoiledTimestamp = "1547036605"; String spoiledParams = "id=57db52e04e2f4001b555f79813a0f503&mccmnc=20409&ported=0&recipient=31667788880&reference=curvy&status=delivered&statusDatetime=2019-01-09T12%3A23%3A23%2B00%3A00"; byte[] spoiledBody = getBytes("get shit spoiled"); assertTrue( "Definitely valid signature is threaten as invalid", requestSigner.isMatch(requestSignature, new Request(requestTimestamp, requestParams, requestBody)) ); assertFalse( "Invalid signature is threaten as invalid", requestSigner.isMatch(spoiledSignature, new Request(requestTimestamp, requestParams, requestBody)) ); assertFalse( "Signature is still valid with replaced timestamp", requestSigner.isMatch(requestSignature, new Request(spoiledTimestamp, requestParams, requestBody)) ); assertFalse( "Signature is still valid with replaced params", requestSigner.isMatch(requestSignature, new Request(requestTimestamp, spoiledParams, requestBody)) ); assertFalse( "Signature is still valid with replaced body", requestSigner.isMatch(requestSignature, new Request(requestTimestamp, requestParams, spoiledBody)) ); }
public boolean isMatch(String expectedSignature, Request request) { try { return isMatch(Base64.decode(expectedSignature), request); } catch (IOException e) { throw new RequestSigningException(e); } }
RequestSigner { public boolean isMatch(String expectedSignature, Request request) { try { return isMatch(Base64.decode(expectedSignature), request); } catch (IOException e) { throw new RequestSigningException(e); } } }
RequestSigner { public boolean isMatch(String expectedSignature, Request request) { try { return isMatch(Base64.decode(expectedSignature), request); } catch (IOException e) { throw new RequestSigningException(e); } } RequestSigner(byte[] key); }
RequestSigner { public boolean isMatch(String expectedSignature, Request request) { try { return isMatch(Base64.decode(expectedSignature), request); } catch (IOException e) { throw new RequestSigningException(e); } } RequestSigner(byte[] key); boolean isMatch(String expectedSignature, Request request); boolean isMatch(byte[] expectedSignature, Request request); }
RequestSigner { public boolean isMatch(String expectedSignature, Request request) { try { return isMatch(Base64.decode(expectedSignature), request); } catch (IOException e) { throw new RequestSigningException(e); } } RequestSigner(byte[] key); boolean isMatch(String expectedSignature, Request request); boolean isMatch(byte[] expectedSignature, Request request);  }