本文整理汇总了Java中org.apache.commons.codec.digest.HmacAlgorithms类的典型用法代码示例。如果您正苦于以下问题:Java HmacAlgorithms类的具体用法?Java HmacAlgorithms怎么用?Java HmacAlgorithms使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HmacAlgorithms类属于org.apache.commons.codec.digest包,在下文中一共展示了HmacAlgorithms类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getHmacAlgorithm
import org.apache.commons.codec.digest.HmacAlgorithms; //导入依赖的package包/类
private static HmacAlgorithms getHmacAlgorithm(final String signatureScheme)
{
if (isBlank(signatureScheme))
{
return null;
}
final String algo = StringUtils.remove(signatureScheme, '-');
for (final HmacAlgorithms ha : HmacAlgorithms.values())
{
if (equalsIgnoreCase(ha.toString(), algo))
{
return ha;
}
}
throw new IllegalArgumentException("Unsupported signature scheme: " + signatureScheme);
}
示例2: testSessionFromUri
import org.apache.commons.codec.digest.HmacAlgorithms; //导入依赖的package包/类
private static void testSessionFromUri(final URI shellUri,
final byte[] hmacKey,
final HmacAlgorithms hmacAlgorithm) throws IOException
{
LOGGER.info("\n\n*** CONNECT BY URI ***\n");
LOGGER.info("Attempting connection by URI: {}...", shellUri);
try (Japyter japyter = Japyter.fromUri(shellUri, hmacKey, hmacAlgorithm)
.withUserName("it-test2")
.build())
{
Validate.notNull(japyter.getControl());
Validate.notNull(japyter.getHeartbeat());
Validate.notNull(japyter.getIoPub());
Validate.notNull(japyter.getSession());
Validate.notNull(japyter.getShell());
Validate.isTrue(japyter.getStdin() == null);
LOGGER.info("All good! Closing test session now...\n");
}
}
示例3: fromUri
import org.apache.commons.codec.digest.HmacAlgorithms; //导入依赖的package包/类
/**
* Creates a new {@link Builder} instance for configuring and instantiating a new
* {@link Japyter} instance, which first retrieves all the connection information from a call (
* <code>connect_request</code> request) to the provided control or shell ZeroMQ router.
*
* @param controlOrShell a {@link URI} that points to either a shell or control ZeroMQ router.
* @param hmacKey the request HMAC signing key, or null if request signature is disabled on the
* kernel.
* @param hmacAlgorithm the request HMAC signing algorithm, or null if request signature is
* disabled on the kernel.
* @throws IOException in case anything goes wrong when retrieving the network configuration.
*/
public static Builder fromUri(final URI controlOrShell,
final byte[] hmacKey,
final HmacAlgorithms hmacAlgorithm) throws IOException
{
LOGGER.info("Fetching connection information from: {}",
notNull(controlOrShell, "controlOrShell can't be null"));
final Protocol protocol = new Protocol(hmacKey, hmacAlgorithm);
try (Session tempSession = new Session(Japyter.class.getName(), protocol, 3000, 1))
{
final Shell tempShell = new Shell(controlOrShell.toString(), tempSession);
final ConnectReply connectReply = tempShell.connect();
final Config config = new Config();
config.withControlPort(connectReply.getControl())
.withHbPort(connectReply.getHb())
.withIopubPort(connectReply.getIopub())
.withIp(controlOrShell.getHost())
.withKey(hmacKey != null ? new String(hmacKey, Protocol.ENCODING) : null)
.withShellPort(connectReply.getShell())
.withSignatureScheme(hmacAlgorithm != null ? hmacAlgorithm.toString() : null)
.withStdinPort(connectReply.getStdin())
.withTransport(controlOrShell.getScheme());
LOGGER.info("Connection information received: {}, losing temporary session", connectReply);
return fromConfig(config);
}
}
示例4: Protocol
import org.apache.commons.codec.digest.HmacAlgorithms; //导入依赖的package包/类
public Protocol(final byte[] hmacKey, final HmacAlgorithms hmacAlgorithm)
{
this.hmacAlgorithm = hmacAlgorithm;
this.hmacKey = ArrayUtils.clone(hmacKey);
if (hmacAlgorithm != null && hmacKey != null)
{
LOGGER.info("HMAC signature enabled with: {}", hmacAlgorithm);
}
else
{
LOGGER.info("HMAC signature is disabled");
}
}
示例5: computeHMAC
import org.apache.commons.codec.digest.HmacAlgorithms; //导入依赖的package包/类
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));
}
示例6: hmacSHA256Base64
import org.apache.commons.codec.digest.HmacAlgorithms; //导入依赖的package包/类
private static String hmacSHA256Base64(String key, String code) {
return Base64.getEncoder().encodeToString(new HmacUtils(HmacAlgorithms.HMAC_SHA_256, key).hmac(code));
}
示例7: sign
import org.apache.commons.codec.digest.HmacAlgorithms; //导入依赖的package包/类
/**
* do a HMac sha256 sign
*
* @param stringData
* data as string
* @param key
* key
* @return signature
*/
protected byte[] sign(final String stringData, final byte[] key) {
return new HmacUtils(HmacAlgorithms.HMAC_SHA_256, key).hmac(stringData);
}