本文整理了Java中javax.crypto.Mac.reset()
方法的一些代码示例,展示了Mac.reset()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mac.reset()
方法的具体详情如下:
包路径:javax.crypto.Mac
类名称:Mac
方法名:reset
[英]Resets this Mac instance to its initial state.
This Mac instance is reverted to its initial state and can be used to start the next MAC computation with the same parameters or initialized with different parameters.
[中]将此Mac实例重置为其初始状态。
此Mac实例还原为其初始状态,可用于使用相同参数启动下一个Mac计算,或使用不同参数初始化。
代码示例来源:origin: commons-codec/commons-codec
/**
* Resets and then updates the given {@link Mac} with the value.
*
* @param mac
* the initialized {@link Mac} to update
* @param valueToDigest
* the value to update the {@link Mac} with (maybe null or empty)
* @return the updated {@link Mac}
* @throws IllegalStateException
* if the Mac was not initialized
*/
public static Mac updateHmac(final Mac mac, final byte[] valueToDigest) {
mac.reset();
mac.update(valueToDigest);
return mac;
}
代码示例来源:origin: looly/hutool
/**
* 生成摘要
*
* @param data 数据bytes
* @return 摘要bytes
*/
public byte[] digest(byte[] data) {
byte[] result;
try {
result = mac.doFinal(data);
} finally {
mac.reset();
}
return result;
}
代码示例来源:origin: looly/hutool
/**
* 生成摘要
*
* @param data 数据bytes
* @return 摘要bytes
*/
public byte[] digest(byte[] data) {
byte[] result;
try {
result = mac.doFinal(data);
} finally {
mac.reset();
}
return result;
}
代码示例来源:origin: apache/drill
/**
* Updates the given {@link Mac}. This generates a digest for valueToDigest and the key the Mac was initialized
*
* @param mac
* the initialized {@link Mac} to update
* @param valueToDigest
* the value to update the {@link Mac} with (maybe null or empty)
* @return the updated {@link Mac}
* @throws IllegalStateException
* if the Mac was not initialized
* @since 1.x
*/
public static Mac updateHmac(final Mac mac, final byte[] valueToDigest) {
mac.reset();
mac.update(valueToDigest);
return mac;
}
代码示例来源:origin: commons-codec/commons-codec
/**
* Resets and then updates the given {@link Mac} with the value.
*
* @param mac
* the initialized {@link Mac} to update
* @param valueToDigest
* the value to update the {@link Mac} with
* <p>
* The InputStream must not be null and will not be closed
* </p>
* @return the updated {@link Mac}
* @throws IOException
* If an I/O error occurs.
* @throws IllegalStateException
* If the Mac was not initialized
*/
public static Mac updateHmac(final Mac mac, final InputStream valueToDigest) throws IOException {
mac.reset();
final byte[] buffer = new byte[STREAM_BUFFER_LENGTH];
int read = valueToDigest.read(buffer, 0, STREAM_BUFFER_LENGTH);
while (read > -1) {
mac.update(buffer, 0, read);
read = valueToDigest.read(buffer, 0, STREAM_BUFFER_LENGTH);
}
return mac;
}
代码示例来源:origin: commons-codec/commons-codec
/**
* Resets and then updates the given {@link Mac} with the value.
*
* @param mac
* the initialized {@link Mac} to update
* @param valueToDigest
* the value to update the {@link Mac} with (maybe null or empty)
* @return the updated {@link Mac}
* @throws IllegalStateException
* if the Mac was not initialized
*/
public static Mac updateHmac(final Mac mac, final String valueToDigest) {
mac.reset();
mac.update(StringUtils.getBytesUtf8(valueToDigest));
return mac;
}
代码示例来源:origin: apache/drill
/**
* Updates the given {@link Mac}. This generates a digest for valueToDigest and the key the Mac was initialized
*
* @param mac
* the initialized {@link Mac} to update
* @param valueToDigest
* the value to update the {@link Mac} with
* <p>
* The InputStream must not be null and will not be closed
* </p>
* @return the updated {@link Mac}
* @throws IOException
* If an I/O error occurs.
* @throws IllegalStateException
* If the Mac was not initialized
* @since 1.x
*/
public static Mac updateHmac(final Mac mac, final InputStream valueToDigest) throws IOException {
mac.reset();
final byte[] buffer = new byte[STREAM_BUFFER_LENGTH];
int read = valueToDigest.read(buffer, 0, STREAM_BUFFER_LENGTH);
while (read > -1) {
mac.update(buffer, 0, read);
read = valueToDigest.read(buffer, 0, STREAM_BUFFER_LENGTH);
}
return mac;
}
代码示例来源:origin: apache/drill
/**
* Updates the given {@link Mac}. This generates a digest for valueToDigest and the key the Mac was initialized
*
* @param mac
* the initialized {@link Mac} to update
* @param valueToDigest
* the value to update the {@link Mac} with (maybe null or empty)
* @return the updated {@link Mac}
* @throws IllegalStateException
* if the Mac was not initialized
* @since 1.x
*/
public static Mac updateHmac(final Mac mac, final String valueToDigest) {
mac.reset();
mac.update(StringUtils.getBytesUtf8(valueToDigest));
return mac;
}
}
代码示例来源:origin: looly/hutool
/**
* 生成摘要
*
* @param data {@link InputStream} 数据流
* @param bufferLength 缓存长度,不足1使用 {@link IoUtil#DEFAULT_BUFFER_SIZE} 做为默认值
* @return 摘要bytes
*/
public byte[] digest(InputStream data, int bufferLength) {
if (bufferLength < 1) {
bufferLength = IoUtil.DEFAULT_BUFFER_SIZE;
}
byte[] buffer = new byte[bufferLength];
byte[] result = null;
try {
int read = data.read(buffer, 0, bufferLength);
while (read > -1) {
mac.update(buffer, 0, read);
read = data.read(buffer, 0, bufferLength);
}
result = mac.doFinal();
} catch (IOException e) {
throw new CryptoException(e);
}finally{
mac.reset();
}
return result;
}
代码示例来源:origin: looly/hutool
/**
* 生成摘要
*
* @param data {@link InputStream} 数据流
* @param bufferLength 缓存长度,不足1使用 {@link IoUtil#DEFAULT_BUFFER_SIZE} 做为默认值
* @return 摘要bytes
*/
public byte[] digest(InputStream data, int bufferLength) {
if (bufferLength < 1) {
bufferLength = IoUtil.DEFAULT_BUFFER_SIZE;
}
byte[] buffer = new byte[bufferLength];
byte[] result = null;
try {
int read = data.read(buffer, 0, bufferLength);
while (read > -1) {
mac.update(buffer, 0, read);
read = data.read(buffer, 0, bufferLength);
}
result = mac.doFinal();
} catch (IOException e) {
throw new CryptoException(e);
}finally{
mac.reset();
}
return result;
}
代码示例来源:origin: AsyncHttpClient/async-http-client
private byte[] digest(ConsumerKey consumerAuth, RequestToken userAuth, ByteBuffer message) throws InvalidKeyException {
StringBuilder sb = StringBuilderPool.DEFAULT.stringBuilder();
Utf8UrlEncoder.encodeAndAppendQueryElement(sb, consumerAuth.getSecret());
sb.append('&');
if (userAuth != null && userAuth.getSecret() != null) {
Utf8UrlEncoder.encodeAndAppendQueryElement(sb, userAuth.getSecret());
}
byte[] keyBytes = StringUtils.charSequence2Bytes(sb, UTF_8);
SecretKeySpec signingKey = new SecretKeySpec(keyBytes, HMAC_SHA1_ALGORITHM);
mac.init(signingKey);
mac.reset();
mac.update(message);
return mac.doFinal();
}
代码示例来源:origin: square/keywhiz
Mac mac = initMac(key);
for (int roundNum = 1; roundNum <= n; roundNum++) {
mac.reset();
ByteBuffer t = ByteBuffer.allocate(hashRound.length + info.length + 1);
t.put(hashRound);
代码示例来源:origin: wildfly/wildfly
mac.reset();
byte[] saltedPassword = initialResult.getScramDigestPassword().getDigest();
mac.init(new SecretKeySpec(saltedPassword, mac.getAlgorithm()));
mac.reset();
mac.init(new SecretKeySpec(storedKey, mac.getAlgorithm()));
final byte[] clientFirstMessage = clientMessage.getInitialResponse().getRawMessageBytes();
mac.reset();
mac.init(new SecretKeySpec(saltedPassword, mac.getAlgorithm()));
mac.update(ScramUtil.SERVER_KEY_BYTES);
mac.reset();
mac.init(new SecretKeySpec(serverKey, mac.getAlgorithm()));
mac.update(clientFirstMessage, clientFirstMessageBareStart, clientFirstMessage.length - clientFirstMessageBareStart);
代码示例来源:origin: com.ning/async-http-client
public synchronized byte[] digest(ByteBuffer message) {
mac.reset();
mac.update(message);
return mac.doFinal();
}
}
代码示例来源:origin: i2p/i2p.i2p
mac.reset();
mac.update(out, 0, 32);
mac.update(tmp, 0, ilen + 1);
代码示例来源:origin: hierynomus/smbj
@Override
public void reset() {
mac.reset();
}
}
代码示例来源:origin: com.hierynomus/smbj
@Override
public void reset() {
mac.reset();
}
}
代码示例来源:origin: org.asynchttpclient/async-http-client-api
public synchronized byte[] digest(ByteBuffer message) {
mac.reset();
mac.update(message);
return mac.doFinal();
}
}
代码示例来源:origin: freenet/fred
/**
* Generates the MAC of only the specified bytes. The buffer is cleared before
* processing the input to ensure that no extra data is included. Once the MAC
* has been generated, the buffer is cleared again.
* @param input
* @return The Message Authentication Code
*/
public final ByteBuffer genMac(byte[]... input){
mac.reset();
addBytes(input);
return genMac();
}
代码示例来源:origin: freenet/fred
/**
* Generates the MAC of only the specified bytes. The buffer is cleared before
* processing the input to ensure that no extra data is included. Once the MAC
* has been generated, the buffer is cleared again.
* @param input
* @return The Message Authentication Code
*/
public final ByteBuffer genMac(ByteBuffer input){
mac.reset();
addBytes(input);
return genMac();
}
内容来源于网络,如有侵权,请联系作者删除!