本文整理汇总了Java中org.spongycastle.crypto.macs.HMac类的典型用法代码示例。如果您正苦于以下问题:Java HMac类的具体用法?Java HMac怎么用?Java HMac使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HMac类属于org.spongycastle.crypto.macs包,在下文中一共展示了HMac类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decrypt
import org.spongycastle.crypto.macs.HMac; //导入依赖的package包/类
public static byte[] decrypt(ECPoint ephem, BigInteger prv, byte[] IV, byte[] cipher, byte[] macData) throws InvalidCipherTextException {
AESFastEngine aesFastEngine = new AESFastEngine();
EthereumIESEngine iesEngine = new EthereumIESEngine(
new ECDHBasicAgreement(),
new ConcatKDFBytesGenerator(new SHA256Digest()),
new HMac(new SHA256Digest()),
new SHA256Digest(),
new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));
byte[] d = new byte[] {};
byte[] e = new byte[] {};
IESParameters p = new IESWithCipherParameters(d, e, KEY_SIZE, KEY_SIZE);
ParametersWithIV parametersWithIV =
new ParametersWithIV(p, IV);
iesEngine.init(false, new ECPrivateKeyParameters(prv, CURVE), new ECPublicKeyParameters(ephem, CURVE), parametersWithIV);
return iesEngine.processBlock(cipher, 0, cipher.length, macData);
}
示例2: decryptSimple
import org.spongycastle.crypto.macs.HMac; //导入依赖的package包/类
/**
* Encryption equivalent to the Crypto++ default ECIES<ECP> settings:
*
* DL_KeyAgreementAlgorithm: DL_KeyAgreementAlgorithm_DH<struct ECPPoint,struct EnumToType<enum CofactorMultiplicationOption,0> >
* DL_KeyDerivationAlgorithm: DL_KeyDerivationAlgorithm_P1363<struct ECPPoint,0,class P1363_KDF2<class SHA1> >
* DL_SymmetricEncryptionAlgorithm: DL_EncryptionAlgorithm_Xor<class HMAC<class SHA1>,0>
* DL_PrivateKey: DL_Key<ECPPoint>
* DL_PrivateKey_EC<class ECP>
*
* Used for Whisper V3
*/
public static byte[] decryptSimple(BigInteger privKey, byte[] cipher) throws IOException, InvalidCipherTextException {
EthereumIESEngine iesEngine = new EthereumIESEngine(
new ECDHBasicAgreement(),
new MGF1BytesGeneratorExt(new SHA1Digest(), 1),
new HMac(new SHA1Digest()),
new SHA1Digest(),
null);
IESParameters p = new IESParameters(null, null, KEY_SIZE);
ParametersWithIV parametersWithIV = new ParametersWithIV(p, new byte[0]);
iesEngine.setHashMacKey(false);
iesEngine.init(new ECPrivateKeyParameters(privKey, CURVE), parametersWithIV,
new ECIESPublicKeyParser(ECKey.CURVE));
return iesEngine.processBlock(cipher, 0, cipher.length);
}
示例3: makeIESEngine
import org.spongycastle.crypto.macs.HMac; //导入依赖的package包/类
private static EthereumIESEngine makeIESEngine(boolean isEncrypt, ECPoint pub, BigInteger prv, byte[] IV) {
AESFastEngine aesFastEngine = new AESFastEngine();
EthereumIESEngine iesEngine = new EthereumIESEngine(
new ECDHBasicAgreement(),
new ConcatKDFBytesGenerator(new SHA256Digest()),
new HMac(new SHA256Digest()),
new SHA256Digest(),
new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));
byte[] d = new byte[] {};
byte[] e = new byte[] {};
IESParameters p = new IESWithCipherParameters(d, e, KEY_SIZE, KEY_SIZE);
ParametersWithIV parametersWithIV = new ParametersWithIV(p, IV);
iesEngine.init(isEncrypt, new ECPrivateKeyParameters(prv, CURVE), new ECPublicKeyParameters(pub, CURVE), parametersWithIV);
return iesEngine;
}
示例4: makeIESEngine
import org.spongycastle.crypto.macs.HMac; //导入依赖的package包/类
private static EthereumIESEngine makeIESEngine(boolean isEncrypt, ECPoint pub, BigInteger prv, byte[] IV) {
AESFastEngine aesFastEngine = new AESFastEngine();
EthereumIESEngine iesEngine = new EthereumIESEngine(
new ECDHBasicAgreement(),
new ConcatKDFBytesGenerator(new SHA256Digest()),
new HMac(new SHA256Digest()),
new SHA256Digest(),
new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));
byte[] d = new byte[] {};
byte[] e = new byte[] {};
IESParameters p = new IESWithCipherParameters(d, e, KEY_SIZE, KEY_SIZE);
ParametersWithIV parametersWithIV = new ParametersWithIV(p, IV);
iesEngine.init(isEncrypt, new ECPrivateKeyParameters(prv, curve), new ECPublicKeyParameters(pub, curve), parametersWithIV);
return iesEngine;
}
示例5: decrypt
import org.spongycastle.crypto.macs.HMac; //导入依赖的package包/类
public static byte[] decrypt(ECPoint ephem, BigInteger prv, byte[] iv, byte[] cipher, byte[] macData) throws InvalidCipherTextException {
AESFastEngine aesFastEngine = new AESFastEngine();
EthereumIESEngine iesEngine = new EthereumIESEngine(
new ECDHBasicAgreement(),
new ConcatKDFBytesGenerator(new SHA256Digest()),
new HMac(new SHA256Digest()),
new SHA256Digest(),
new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));
byte[] d = new byte[] {};
byte[] e = new byte[] {};
IESParameters p = new IESWithCipherParameters(d, e, KEY_SIZE, KEY_SIZE);
ParametersWithIV parametersWithIV =
new ParametersWithIV(p, iv);
iesEngine.init(false, new ECPrivateKeyParameters(prv, CURVE), new ECPublicKeyParameters(ephem, CURVE), parametersWithIV);
return iesEngine.processBlock(cipher, 0, cipher.length, macData);
}
示例6: encryptSimple
import org.spongycastle.crypto.macs.HMac; //导入依赖的package包/类
/**
* Encryption equivalent to the Crypto++ default ECIES<ECP> settings:
*
* DL_KeyAgreementAlgorithm: DL_KeyAgreementAlgorithm_DH<struct ECPPoint,struct EnumToType<enum CofactorMultiplicationOption,0> >
* DL_KeyDerivationAlgorithm: DL_KeyDerivationAlgorithm_P1363<struct ECPPoint,0,class P1363_KDF2<class SHA1> >
* DL_SymmetricEncryptionAlgorithm: DL_EncryptionAlgorithm_Xor<class HMAC<class SHA1>,0>
* DL_PrivateKey: DL_Key<ECPPoint>
* DL_PrivateKey_EC<class ECP>
*
* Used for Whisper V3
*/
public static byte[] encryptSimple(ECPoint pub, byte[] plaintext) throws IOException, InvalidCipherTextException {
EthereumIESEngine iesEngine = new EthereumIESEngine(
new ECDHBasicAgreement(),
new MGF1BytesGeneratorExt(new SHA1Digest(), 1),
new HMac(new SHA1Digest()),
new SHA1Digest(),
null);
IESParameters p = new IESParameters(null, null, KEY_SIZE);
ParametersWithIV parametersWithIV = new ParametersWithIV(p, new byte[0]);
iesEngine.setHashMacKey(false);
ECKeyPairGenerator eGen = new ECKeyPairGenerator();
SecureRandom random = new SecureRandom();
KeyGenerationParameters gParam = new ECKeyGenerationParameters(CURVE, random);
eGen.init(gParam);
EphemeralKeyPairGenerator ephemeralKeyPairGenerator =
new EphemeralKeyPairGenerator(/*testGen*/eGen, new ECIESPublicKeyEncoder());
iesEngine.init(new ECPublicKeyParameters(pub, CURVE), parametersWithIV, ephemeralKeyPairGenerator);
return iesEngine.processBlock(plaintext, 0, plaintext.length);
}
示例7: makeIESEngine
import org.spongycastle.crypto.macs.HMac; //导入依赖的package包/类
private static EthereumIESEngine makeIESEngine(boolean isEncrypt, ECPoint pub, BigInteger prv, byte[] iv) {
AESFastEngine aesFastEngine = new AESFastEngine();
EthereumIESEngine iesEngine = new EthereumIESEngine(
new ECDHBasicAgreement(),
new ConcatKDFBytesGenerator(new SHA256Digest()),
new HMac(new SHA256Digest()),
new SHA256Digest(),
new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));
byte[] d = new byte[] {};
byte[] e = new byte[] {};
IESParameters p = new IESWithCipherParameters(d, e, KEY_SIZE, KEY_SIZE);
ParametersWithIV parametersWithIV = new ParametersWithIV(p, iv);
iesEngine.init(isEncrypt, new ECPrivateKeyParameters(prv, CURVE), new ECPublicKeyParameters(pub, CURVE), parametersWithIV);
return iesEngine;
}
示例8: encryptSimple
import org.spongycastle.crypto.macs.HMac; //导入依赖的package包/类
/**
* Encryption equivalent to the Crypto++ default ECIES<ECP> settings:
*
* DL_KeyAgreementAlgorithm: DL_KeyAgreementAlgorithm_DH<struct ECPPoint,struct EnumToType<enum CofactorMultiplicationOption,0> >
* DL_KeyDerivationAlgorithm: DL_KeyDerivationAlgorithm_P1363<struct ECPPoint,0,class P1363_KDF2<class SHA1> >
* DL_SymmetricEncryptionAlgorithm: DL_EncryptionAlgorithm_Xor<class HMAC<class SHA1>,0>
* DL_PrivateKey: DL_Key<ECPPoint>
* DL_PrivateKey_EC<class ECP>
*
* Used for Whisper V3
*/
public static byte[] encryptSimple(ECPoint pub, byte[] plaintext) throws IOException, InvalidCipherTextException {
EthereumIESEngine iesEngine = new EthereumIESEngine(
new ECDHBasicAgreement(),
new MGF1BytesGeneratorExt(new SHA1Digest(), 1),
new HMac(new SHA1Digest()),
new SHA1Digest(),
null);
IESParameters p = new IESParameters(null, null, KEY_SIZE);
ParametersWithIV parametersWithIV = new ParametersWithIV(p, new byte[0]);
iesEngine.setHashMacKey(false);
ECKeyPairGenerator eGen = new ECKeyPairGenerator();
SecureRandom random = new SecureRandom();
KeyGenerationParameters gParam = new ECKeyGenerationParameters(CURVE, random);
eGen.init(gParam);
// AsymmetricCipherKeyPairGenerator testGen = new AsymmetricCipherKeyPairGenerator() {
// ECKey priv = ECKey.fromPrivate(Hex.decode("d0b043b4c5d657670778242d82d68a29d25d7d711127d17b8e299f156dad361a"));
//
// @Override
// public void init(KeyGenerationParameters keyGenerationParameters) {
// }
//
// @Override
// public AsymmetricCipherKeyPair generateKeyPair() {
// return new AsymmetricCipherKeyPair(new ECPublicKeyParameters(priv.getPubKeyPoint(), CURVE),
// new ECPrivateKeyParameters(priv.getPrivKey(), CURVE));
// }
// };
EphemeralKeyPairGenerator ephemeralKeyPairGenerator =
new EphemeralKeyPairGenerator(/*testGen*/eGen, new ECIESPublicKeyEncoder());
iesEngine.init(new ECPublicKeyParameters(pub, CURVE), parametersWithIV, ephemeralKeyPairGenerator);
return iesEngine.processBlock(plaintext, 0, plaintext.length);
}
示例9: getEngine
import org.spongycastle.crypto.macs.HMac; //导入依赖的package包/类
private IESEngine getEngine() {
BasicAgreement agreement = new ECDHCBasicAgreement();
DerivationFunction kdf = new KDF2BytesGenerator(new SHA256Digest());
Mac mac = new HMac(new SHA256Digest());
BlockCipher cipher = new CBCBlockCipher(new AESLightEngine());
PaddedBufferedBlockCipher pad = new PaddedBufferedBlockCipher(cipher);
return new IESEngine(agreement, kdf, mac, pad);
}
示例10: counterModeKdf
import org.spongycastle.crypto.macs.HMac; //导入依赖的package包/类
private byte[] counterModeKdf(byte[] secret, byte[] label, long context) {
if(secret.length != CIPHER_KEY_BYTES)
throw new IllegalArgumentException();
if(Arrays.equals(secret, BLANK_SECRET))
throw new IllegalArgumentException();
// The label must be null-terminated
if(label[label.length - 1] != '\0')
throw new IllegalArgumentException();
// Initialise the PRF
Mac prf = new HMac(new SHA384Digest());
KeyParameter k = new KeyParameter(secret);
prf.init(k);
int macLength = prf.getMacSize();
// The output of the PRF must be long enough to use as a key
if(macLength < CIPHER_KEY_BYTES) throw new RuntimeException();
byte[] mac = new byte[macLength], output = new byte[CIPHER_KEY_BYTES];
prf.update((byte) 0); // Counter
prf.update(label, 0, label.length); // Null-terminated
byte[] contextBytes = new byte[4];
ByteUtils.writeUint32(context, contextBytes, 0);
prf.update(contextBytes, 0, contextBytes.length);
prf.update((byte) CIPHER_KEY_BYTES); // Output length
prf.doFinal(mac, 0);
System.arraycopy(mac, 0, output, 0, output.length);
ByteUtils.erase(mac);
ByteUtils.erase(k.getKey());
return output;
}
示例11: createHmacSha512Digest
import org.spongycastle.crypto.macs.HMac; //导入依赖的package包/类
static HMac createHmacSha512Digest(byte[] key) {
SHA512Digest digest = new SHA512Digest();
HMac hMac = new HMac(digest);
hMac.init(new KeyParameter(key));
return hMac;
}
示例12: ECIES
import org.spongycastle.crypto.macs.HMac; //导入依赖的package包/类
public ECIES() {
super(new IESEngine(new ECDHBasicAgreement(),
new KDF2BytesGenerator(new SHA1Digest()),
new HMac(new SHA1Digest())));
}
示例13: ECIESwithCipher
import org.spongycastle.crypto.macs.HMac; //导入依赖的package包/类
public ECIESwithCipher(BlockCipher cipher) {
super(new IESEngine(new ECDHBasicAgreement(),
new KDF2BytesGenerator(new SHA1Digest()),
new HMac(new SHA1Digest()),
new PaddedBufferedBlockCipher(cipher)));
}
示例14: OldECIES
import org.spongycastle.crypto.macs.HMac; //导入依赖的package包/类
public OldECIES() {
super(new OldIESEngine(new ECDHBasicAgreement(),
new KDF2BytesGenerator(new SHA1Digest()),
new HMac(new SHA1Digest())));
}
示例15: OldECIESwithCipher
import org.spongycastle.crypto.macs.HMac; //导入依赖的package包/类
public OldECIESwithCipher(BlockCipher baseCipher) {
super(new OldIESEngine(new ECDHBasicAgreement(),
new KDF2BytesGenerator(new SHA1Digest()),
new HMac(new SHA1Digest()),
new PaddedBufferedBlockCipher(baseCipher)));
}