org.apache.commons.codec.digest.HmacAlgorithms Java Examples
The following examples show how to use
org.apache.commons.codec.digest.HmacAlgorithms.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MatrixHttpClient.java From matrix-java-sdk with GNU Affero General Public License v3.0 | 6 votes |
@Override public void register(MatrixPasswordCredentials credentials, String sharedSecret, boolean admin) { // As per synapse registration script: // https://github.com/matrix-org/synapse/blob/master/scripts/register_new_matrix_user#L28 String value = credentials.getLocalPart() + "\0" + credentials.getPassword() + "\0" + (admin ? "admin" : "notadmin"); String mac = new HmacUtils(HmacAlgorithms.HMAC_SHA_1, sharedSecret).hmacHex(value); JsonObject body = new JsonObject(); body.addProperty("user", credentials.getLocalPart()); body.addProperty("password", credentials.getPassword()); body.addProperty("mac", mac); body.addProperty("type", "org.matrix.login.shared_secret"); body.addProperty("admin", false); URL url = getPath("client", "api", "v1", "register"); updateContext(execute(new Request.Builder().post(getJsonBody(body)).url(url))); }
Example #2
Source File: PatreonServiceImpl.java From JuniperBot with GNU General Public License v3.0 | 6 votes |
@PostConstruct private void init() { List<PatreonUser> activeUsers = repository.findActive(); activeUsers.forEach(this::enableFeatures); String accessToken = workerProperties.getPatreon().getAccessToken(); if (StringUtils.isNotEmpty(accessToken)) { creatorApi = new PatreonAPI(accessToken); if (workerProperties.getPatreon().isUpdateEnabled()) { scheduler.scheduleWithFixedDelay(this::update, workerProperties.getPatreon().getUpdateInterval()); } } else { log.warn("No Patreon credentials specified, integration would not work"); } String webhookSecret = workerProperties.getPatreon().getWebhookSecret(); if (StringUtils.isNotEmpty(webhookSecret)) { webHookHmac = new HmacUtils(HmacAlgorithms.HMAC_MD5, webhookSecret); } else { log.warn("No Patreon WebHook secret specified, WebHooks would not work"); } }
Example #3
Source File: InstamojoImpl.java From instamojo-java with MIT License | 6 votes |
@Override public String generateWebhookSignature(Map<String, String> data, String salt) { ArrayList<String> keys = new ArrayList<>(data.keySet()); Collections.sort(keys); StringBuilder sb = new StringBuilder(); for (int index = 0; index < keys.size(); index++) { sb.append(data.get(keys.get(index))); if (index != keys.size() - 1) { sb.append('|'); } } return new HmacUtils(HmacAlgorithms.HMAC_SHA_1, salt).hmacHex(sb.toString()); }
Example #4
Source File: BitBucketServerAuth.java From gocd with Apache License 2.0 | 6 votes |
default void validateAuth(String webhookSecret) { if (exemptFromAuth()) { return; } String signature = request().headers("X-Hub-Signature"); if (isBlank(signature)) { throw die("No HMAC signature specified via 'X-Hub-Signature' header!"); } String expectedSignature = "sha256=" + new HmacUtils(HmacAlgorithms.HMAC_SHA_256, webhookSecret) .hmacHex(request().body()); if (!MessageDigest.isEqual(expectedSignature.getBytes(), signature.getBytes())) { throw die("HMAC signature specified via 'X-Hub-Signature' did not match!"); } if (!"git".equals(scmType())) { throw die("Only 'git' repositories are currently supported!"); } }
Example #5
Source File: ExtensionUtils.java From alf.io with GNU General Public License v3.0 | 5 votes |
public static String computeHMAC(String secret, String... parts) { if(parts == null || parts.length == 0) { return ""; } var text = Arrays.stream(parts).map(StringUtils::trimToEmpty).collect(Collectors.joining("")); return new HmacUtils(HmacAlgorithms.HMAC_SHA_256, secret).hmacHex(text); }
Example #6
Source File: GitHubAuth.java From gocd with Apache License 2.0 | 5 votes |
default void validateAuth(String secret) { String signature = request().headers("X-Hub-Signature"); if (isBlank(signature)) { throw die("No HMAC signature specified via 'X-Hub-Signature' header!"); } String expectedSignature = "sha1=" + new HmacUtils(HmacAlgorithms.HMAC_SHA_1, secret).hmacHex(request().body()); if (!MessageDigest.isEqual(expectedSignature.getBytes(), signature.getBytes())) { throw die("HMAC signature specified via 'X-Hub-Signature' did not match!"); } }
Example #7
Source File: SimpleTokenManager.java From littleca with Apache License 2.0 | 4 votes |
public SimpleTokenManager(String hmacKey) { this.hmac=new HmacUtils(HmacAlgorithms.HMAC_MD5, hmacKey); }
Example #8
Source File: SimpleTokenManager.java From littleca with Apache License 2.0 | 4 votes |
public String createToken(String hmacKey,Map<String,String> data) { String signData=mapToString(data); String sign = Base64.encodeBase64URLSafeString(new HmacUtils(HmacAlgorithms.HMAC_MD5, hmacKey).hmac(signData)); String token=Base64.encodeBase64URLSafeString(signData.getBytes())+"."+sign; return token; }
Example #9
Source File: SimpleTokenManager.java From littleca with Apache License 2.0 | 4 votes |
public SimpleTokenManager(String hmacKey) { this.hmac=new HmacUtils(HmacAlgorithms.HMAC_MD5, hmacKey); }
Example #10
Source File: SimpleTokenManager.java From littleca with Apache License 2.0 | 4 votes |
public String createToken(String hmacKey,Map<String,String> data) { String signData=mapToString(data); String sign = Base64.encodeBase64URLSafeString(new HmacUtils(HmacAlgorithms.HMAC_MD5, hmacKey).hmac(signData)); String token=Base64.encodeBase64URLSafeString(signData.getBytes())+"."+sign; return token; }
Example #11
Source File: FacebookBidder.java From prebid-server-java with Apache License 2.0 | 4 votes |
private String makeAuthId(String requestId) { final Mac mac = HmacUtils.getInitializedMac(HmacAlgorithms.HMAC_SHA_256, appSecret.getBytes()); return Hex.encodeHexString(mac.doFinal(requestId != null ? requestId.getBytes() : null)); }
Example #12
Source File: AuthorizationValidationFilter.java From pay-publicapi with MIT License | 4 votes |
private boolean tokenMatchesHmac(String token, String currentHmac) { final String hmacCalculatedFromToken = BaseEncoding.base32Hex() .lowerCase().omitPadding() .encode(new HmacUtils(HmacAlgorithms.HMAC_SHA_1, apiKeyHmacSecret).hmac(token)); return hmacCalculatedFromToken.equals(currentHmac); }
Example #13
Source File: ApiKeyGenerator.java From pay-publicapi with MIT License | 4 votes |
public static String apiKeyValueOf(String token, String secret) { byte[] hmacBytes = new HmacUtils(HmacAlgorithms.HMAC_SHA_1, secret).hmac(token); String encodedHmac = BaseEncoding.base32Hex().lowerCase().omitPadding().encode(hmacBytes); return token + encodedHmac; }
Example #14
Source File: PayPalManager.java From alf.io with GNU General Public License v3.0 | 4 votes |
private static String computeHMAC(CustomerName customerName, String email, String billingAddress, Event event) { return new HmacUtils(HmacAlgorithms.HMAC_SHA_256, event.getPrivateKey()).hmacHex(StringUtils.trimToEmpty(customerName.getFullName()) + StringUtils.trimToEmpty(email) + StringUtils.trimToEmpty(billingAddress)); }
Example #15
Source File: Ticket.java From alf.io with GNU General Public License v3.0 | 4 votes |
public static String hmacSHA256Base64(String key, String code) { return Base64.getEncoder().encodeToString(new HmacUtils(HmacAlgorithms.HMAC_SHA_256, key).hmac(code)); }