本文整理了Java中javax.crypto.Mac.getAlgorithm()
方法的一些代码示例,展示了Mac.getAlgorithm()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mac.getAlgorithm()
方法的具体详情如下:
包路径:javax.crypto.Mac
类名称:Mac
方法名:getAlgorithm
[英]Returns the name of the MAC algorithm.
[中]返回MAC算法的名称。
代码示例来源:origin: apache/kafka
public byte[] hmac(byte[] key, byte[] bytes) throws InvalidKeyException {
mac.init(new SecretKeySpec(key, mac.getAlgorithm()));
return mac.doFinal(bytes);
}
代码示例来源:origin: apache/kafka
public byte[] hi(byte[] str, byte[] salt, int iterations) throws InvalidKeyException {
mac.init(new SecretKeySpec(str, mac.getAlgorithm()));
mac.update(salt);
byte[] u1 = mac.doFinal(new byte[]{0, 0, 0, 1});
byte[] prev = u1;
byte[] result = u1;
for (int i = 2; i <= iterations; i++) {
byte[] ui = hmac(str, prev);
result = xor(result, ui);
prev = ui;
}
return result;
}
代码示例来源:origin: knowm/XChange
public HmacDigest(String algorithm, String secretKey) {
Assert.notNull(algorithm, "Null algorithm");
Assert.notNull(secretKey, "Null secretKey");
try {
mac = Mac.getInstance(algorithm);
mac.init(new SecretKeySpec(secretKey.getBytes(utf8), mac.getAlgorithm()));
} catch (InvalidKeyException | NoSuchAlgorithmException ex) {
throw new IllegalArgumentException(ex);
}
}
代码示例来源:origin: google/guava
@Override
public Hasher newHasher() {
if (supportsClone) {
try {
return new MacHasher((Mac) prototype.clone());
} catch (CloneNotSupportedException e) {
// falls through
}
}
return new MacHasher(getMac(prototype.getAlgorithm(), key));
}
代码示例来源:origin: hierynomus/sshj
mac.init(new SecretKeySpec(key, 0, 20, mac.getAlgorithm()));
代码示例来源:origin: prestodb/presto
@Override
public Hasher newHasher() {
if (supportsClone) {
try {
return new MacHasher((Mac) prototype.clone());
} catch (CloneNotSupportedException e) {
// falls through
}
}
return new MacHasher(getMac(prototype.getAlgorithm(), key));
}
代码示例来源:origin: google/j2objc
@Override
public Hasher newHasher() {
if (supportsClone) {
try {
return new MacHasher((Mac) prototype.clone());
} catch (CloneNotSupportedException e) {
// falls through
}
}
return new MacHasher(getMac(prototype.getAlgorithm(), key));
}
代码示例来源:origin: wildfly/wildfly
@Override
public Hasher newHasher() {
if (supportsClone) {
try {
return new MacHasher((Mac) prototype.clone());
} catch (CloneNotSupportedException e) {
// falls through
}
}
return new MacHasher(getMac(prototype.getAlgorithm(), key));
}
代码示例来源:origin: wildfly/wildfly
mac.init(new SecretKeySpec(password.getDigest(), mac.getAlgorithm()));
byte[] serverKey = mac.doFinal(ScramUtil.SERVER_KEY_BYTES);
if(trace) saslScram.tracef("[C] Server key: %s%n", ByteIterator.ofBytes(serverKey).hexEncode().drainToString());
mac.init(new SecretKeySpec(serverKey, mac.getAlgorithm()));
byte[] clientFirstMessage = finalResponse.getInitialResponse().getRawMessageBytes();
int bareStart = finalResponse.getInitialResponse().getInitialPartIndex();
代码示例来源:origin: wildfly/wildfly
mac.reset();
byte[] saltedPassword = initialResult.getScramDigestPassword().getDigest();
mac.init(new SecretKeySpec(saltedPassword, mac.getAlgorithm()));
mac.update(ScramUtil.CLIENT_KEY_BYTES);
clientKey = mac.doFinal();
mac.init(new SecretKeySpec(storedKey, mac.getAlgorithm()));
final byte[] clientFirstMessage = clientMessage.getInitialResponse().getRawMessageBytes();
final int clientFirstMessageBareStart = clientMessage.getInitialResponse().getInitialPartIndex();
mac.init(new SecretKeySpec(saltedPassword, mac.getAlgorithm()));
mac.update(ScramUtil.SERVER_KEY_BYTES);
serverKey = mac.doFinal();
mac.init(new SecretKeySpec(serverKey, mac.getAlgorithm()));
mac.update(clientFirstMessage, clientFirstMessageBareStart, clientFirstMessage.length - clientFirstMessageBareStart);
mac.update((byte) ',');
代码示例来源:origin: resteasy/Resteasy
public static byte[] sign(byte[] data, Algorithm algorithm, byte[] sharedSecret)
{
try
{
Mac mac = HMACProvider.getMAC(algorithm);
mac.init(new SecretKeySpec(sharedSecret, mac.getAlgorithm()));
mac.update(data);
return mac.doFinal();
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
代码示例来源:origin: wildfly/wildfly
final MessageDigest messageDigest = MessageDigest.getInstance(getMechanism().getMessageDigestName());
mac.init(new SecretKeySpec(saltedPassword, mac.getAlgorithm()));
final byte[] clientKey = mac.doFinal(ScramUtil.CLIENT_KEY_BYTES);
if(trace) saslScram.tracef("[C] Client key: %s", ByteIterator.ofBytes(clientKey).hexEncode().drainToString());
final byte[] storedKey = messageDigest.digest(clientKey);
if(trace) saslScram.tracef("[C] Stored key: %s%n", ByteIterator.ofBytes(storedKey).hexEncode().drainToString());
mac.init(new SecretKeySpec(storedKey, mac.getAlgorithm()));
final byte[] initialResponseBytes = initialResponse.getRawMessageBytes();
mac.update(initialResponseBytes, initialResponse.getInitialPartIndex(), initialResponseBytes.length - initialResponse.getInitialPartIndex());
代码示例来源:origin: org.apache.santuario/xmlsec
/**
* Method engineGetJCEAlgorithmString
* {@inheritDoc}
*
*/
protected String engineGetJCEAlgorithmString() {
return this.macAlgorithm.getAlgorithm();
}
代码示例来源:origin: stackoverflow.com
Mac mac = Mac.getInstance("HmacSHA1");
SecretKeySpec secret = new SecretKeySpec(key.getBytes(), mac.getAlgorithm());
mac.init(secret);
byte[] digest = mac.doFinal(baseString.getBytes());
byte[] result=Base64.encode(digest, DEFAULT);
代码示例来源:origin: RUB-NDS/TLS-Attacker
public JavaMac(String javaName, byte[] key) {
try {
mac = Mac.getInstance(javaName);
mac.init(new SecretKeySpec(key, mac.getAlgorithm()));
} catch (NoSuchAlgorithmException | InvalidKeyException ex) {
throw new UnsupportedOperationException("Mac not supported: " + javaName, ex);
}
}
代码示例来源:origin: iterate-ch/cyberduck
private static byte[] hmacSha1Hash(byte[] salt, String hostname) throws IOException {
try {
final Mac mac = Mac.getInstance("HmacSHA1");
mac.init(new SecretKeySpec(salt, 0, salt.length, mac.getAlgorithm()));
mac.update(hostname.getBytes());
return mac.doFinal();
}
catch(GeneralSecurityException e) {
throw new IOException(e);
}
}
代码示例来源:origin: org.keycloak/keycloak-core
public static byte[] sign(byte[] data, Algorithm algorithm, byte[] sharedSecret) {
try {
Mac mac = getMAC(algorithm);
mac.init(new SecretKeySpec(sharedSecret, mac.getAlgorithm()));
mac.update(data);
return mac.doFinal();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: org.bitbucket.b_c/jose4j
public static void initMacWithKey(Mac mac, Key key) throws org.jose4j.lang.InvalidKeyException
{
try
{
mac.init(key);
}
catch (InvalidKeyException e)
{
throw new org.jose4j.lang.InvalidKeyException("Key is not valid for " + mac.getAlgorithm(), e);
}
}
}
代码示例来源:origin: Baidu-AIP/java-sdk
public static String hmacSha256(String key, String data) throws AipException {
try {
Mac mac = Mac.getInstance("HmacSHA256");
SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(),
mac.getAlgorithm());
mac.init(signingKey);
return encodeHex(mac.doFinal(data.getBytes()));
} catch (Exception e) {
e.printStackTrace();
throw new AipException(-1, "Fail to generate HMAC-SHA256 signature");
}
}
代码示例来源:origin: apache/cxf
public static byte[] computeHmac(byte[] key, Mac hmac, String data) {
SecretKeySpec secretKey = new SecretKeySpec(key, hmac.getAlgorithm());
byte[] digest = computeHmac(secretKey, hmac, data);
// Here we're finished with the SecretKey we created, so we can destroy it
try {
secretKey.destroy();
} catch (DestroyFailedException e) {
// ignore
}
return digest;
}
内容来源于网络,如有侵权,请联系作者删除!