Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marcellodesales/jsonutils-java
https://github.com/marcellodesales/jsonutils-java
Last synced: 26 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/marcellodesales/jsonutils-java
- Owner: marcellodesales
- Created: 2016-09-17T19:38:57.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-09-17T23:31:21.000Z (over 8 years ago)
- Last Synced: 2023-06-30T20:37:09.780Z (over 1 year ago)
- Language: Java
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Json Utils
==========* JSONMinify: properly Minifies JSON to be used on Github HMAC verification, specially for validation of HMAC signatures of Github Enterprise Webhook hooks.
JSONMinify.minify(payload)
-----This is needed for verifying Github Enterprise HMAC Webhook signatures. Since the payload is a JSON payload, it needs to be the minified version of the JSON to properly generate a valid HMAC SHA1 value of the payload. Results are the same as using http://beautifytools.com/json-minifier.php.
```java
/**
* Computes a RFC 2104-compliant HMAC digest using SHA1 of a payloadFrom with a given key
* (secret).
*
* @param payload is the payload provided by the user.
* @param secret is the secret used by the user.
* @return HMAC digest of payloadFrom using secret as key. Will return COMPUTED_INVALID_SIGNATURE
* on any exception during computation.
* @throws InvalidKeyException when the key is invalid.
*/
public static String sha1(String payload, String secret) throws InvalidKeyException {
payload = payload.startsWith("[") || payload.startsWith("{") ? JSONMinify.minify(payload) : payload;final SecretKeySpec keySpec = new SecretKeySpec(secret.getBytes(UTF_8), HMAC_SHA1_ALGORITHM);
try {
Mac mac = Mac.getInstance(HMAC_SHA1_ALGORITHM);
mac.init(keySpec);
final byte[] rawHMACBytes = mac.doFinal(payload.getBytes(UTF_8));return Hex.encodeHexString(rawHMACBytes);
} catch (NoSuchAlgorithmException e) {
return null; // not happening.
}
}
```Gradle Dependency Coodinate
-------```groovy
compile 'com.github.marcellodesales:json-utils:1.0.0'
```Maven Dependency Coordinate
-----* Maven
```xml
com.github.marcellodesales
json-utils
1.0.0```
Dev
=====* Initial Setup in Maven Central: https://issues.sonatype.org/browse/OSSRH-25026