MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / encode

Method encode

samples/JGroups/src/S3_PING.java:1465–1500  ·  view source on GitHub ↗

Calculate the HMAC/SHA1 on a string. @return Signature @throws java.security.NoSuchAlgorithmException If the algorithm does not exist. Unlikely @throws java.security.InvalidKeyException If the key is invalid.

(String awsSecretAccessKey, String canonicalString,
                             boolean urlencode)

Source from the content-addressed store, hash-verified

1463 * If the key is invalid.
1464 */
1465 static String encode(String awsSecretAccessKey, String canonicalString,
1466 boolean urlencode) {
1467 // The following HMAC/SHA1 code for the signature is taken from the
1468 // AWS Platform's implementation of RFC2104 (amazon.webservices.common.Signature)
1469 //
1470 // Acquire an HMAC/SHA1 from the raw key bytes.
1471 SecretKeySpec signingKey=
1472 new SecretKeySpec(awsSecretAccessKey.getBytes(), HMAC_SHA1_ALGORITHM);
1473
1474 // Acquire the MAC instance and initialize with the signing key.
1475 Mac mac=null;
1476 try {
1477 mac=Mac.getInstance(HMAC_SHA1_ALGORITHM);
1478 }
1479 catch(NoSuchAlgorithmException e) {
1480 // should not happen
1481 throw new RuntimeException("Could not find sha1 algorithm", e);
1482 }
1483 try {
1484 mac.init(signingKey);
1485 }
1486 catch(InvalidKeyException e) {
1487 // also should not happen
1488 throw new RuntimeException("Could not initialize the MAC algorithm", e);
1489 }
1490
1491 // Compute the HMAC on the digest, and set it.
1492 String b64=Base64.encodeBytes(mac.doFinal(canonicalString.getBytes()));
1493
1494 if(urlencode) {
1495 return urlencode(b64);
1496 }
1497 else {
1498 return b64;
1499 }
1500 }
1501
1502 static Map paramsForListOptions(String prefix, String marker, Integer maxKeys) {
1503 return paramsForListOptions(prefix, marker, maxKeys, null);

Callers 14

addAuthHeaderMethod · 0.95
urlencodeMethod · 0.45
Z_checksum_handlerFunction · 0.45
__init__Method · 0.45
get_algo_hexsumFunction · 0.45
urlsafe_b64decodeFunction · 0.45
get_uuid_on_contentFunction · 0.45
_unique_idMethod · 0.45
select_ngramsFunction · 0.45
as_unicodeFunction · 0.45

Calls 4

encodeBytesMethod · 0.95
urlencodeMethod · 0.95
getInstanceMethod · 0.80
initMethod · 0.45

Tested by

no test coverage detected