本文整理汇总了Java中org.bouncycastle.crypto.digests.RIPEMD160Digest类的典型用法代码示例。如果您正苦于以下问题:Java RIPEMD160Digest类的具体用法?Java RIPEMD160Digest怎么用?Java RIPEMD160Digest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RIPEMD160Digest类属于org.bouncycastle.crypto.digests包,在下文中一共展示了RIPEMD160Digest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: perform
import org.bouncycastle.crypto.digests.RIPEMD160Digest; //导入依赖的package包/类
public TestResult perform()
{
HMac hmac = new HMac(new RIPEMD160Digest());
byte[] resBuf = new byte[hmac.getMacSize()];
for (int i = 0; i < messages.length; i++)
{
byte[] m = messages[i].getBytes();
if (messages[i].startsWith("0x"))
{
m = Hex.decode(messages[i].substring(2));
}
hmac.init(new KeyParameter(Hex.decode(keys[i])));
hmac.update(m, 0, m.length);
hmac.doFinal(resBuf, 0);
if (!Arrays.areEqual(resBuf, Hex.decode(digests[i])))
{
return new SimpleTestResult(false, getName() + ": Vector " + i + " failed");
}
}
return new SimpleTestResult(true, getName() + ": Okay");
}
示例2: OldPKCS12ParametersGenerator
import org.bouncycastle.crypto.digests.RIPEMD160Digest; //导入依赖的package包/类
/**
* Construct a PKCS 12 Parameters generator. This constructor will
* accept MD5, SHA1, and RIPEMD160.
*
* @param digest the digest to be used as the source of derived keys.
* @exception IllegalArgumentException if an unknown digest is passed in.
*/
public OldPKCS12ParametersGenerator(
Digest digest)
{
this.digest = digest;
if (digest instanceof MD5Digest)
{
u = 128 / 8;
v = 512 / 8;
}
else if (digest instanceof SHA1Digest)
{
u = 160 / 8;
v = 512 / 8;
}
else if (digest instanceof RIPEMD160Digest)
{
u = 160 / 8;
v = 512 / 8;
}
else
{
throw new IllegalArgumentException("Digest " + digest.getAlgorithmName() + " unsupported");
}
}
示例3: PKCS12ParametersGenerator
import org.bouncycastle.crypto.digests.RIPEMD160Digest; //导入依赖的package包/类
/**
* Construct a PKCS 12 Parameters generator. This constructor will
* accept MD5, SHA1, and RIPEMD160.
*
* @param digest the digest to be used as the source of derived keys.
* @exception IllegalArgumentException if an unknown digest is passed in.
*/
public PKCS12ParametersGenerator(
Digest digest)
{
this.digest = digest;
if (digest instanceof MD5Digest)
{
u = 128 / 8;
v = 512 / 8;
}
else if (digest instanceof SHA1Digest)
{
u = 160 / 8;
v = 512 / 8;
}
else if (digest instanceof RIPEMD160Digest)
{
u = 160 / 8;
v = 512 / 8;
}
else
{
throw new IllegalArgumentException("Digest " + digest.getAlgorithmName() + " unsupported");
}
}
示例4: createFromUserAttribute
import org.bouncycastle.crypto.digests.RIPEMD160Digest; //导入依赖的package包/类
public static PgpUserIdNameHash createFromUserAttribute(final PGPUserAttributeSubpacketVector userAttribute) {
assertNotNull(userAttribute, "userAttribute");
final RIPEMD160Digest digest = new RIPEMD160Digest();
// TODO this needs to be extended, if there is ever any other attribute possible, too!
// Currently, image seems to be the only supported attribute. Alternatively, we could get the data via reflection...
final UserAttributeSubpacket subpacket = userAttribute.getSubpacket(UserAttributeSubpacketTags.IMAGE_ATTRIBUTE);
assertNotNull(subpacket, "subpacket");
final byte[] data = assertNotNull(subpacket.getData(), "subpacket.data");
digest.update(data, 0, data.length);
final byte[] out = new byte[digest.getDigestSize()];
digest.doFinal(out, 0);
return new PgpUserIdNameHash(out);
}
示例5: clone
import org.bouncycastle.crypto.digests.RIPEMD160Digest; //导入依赖的package包/类
public Object clone()
throws CloneNotSupportedException
{
Digest d = (Digest)super.clone();
d.digest = new RIPEMD160Digest((RIPEMD160Digest)digest);
return d;
}
示例6: createDigest
import org.bouncycastle.crypto.digests.RIPEMD160Digest; //导入依赖的package包/类
static Digest createDigest(int algorithm)
throws PGPException
{
switch (algorithm)
{
case HashAlgorithmTags.SHA1:
return new SHA1Digest();
case HashAlgorithmTags.SHA224:
return new SHA224Digest();
case HashAlgorithmTags.SHA256:
return new SHA256Digest();
case HashAlgorithmTags.SHA384:
return new SHA384Digest();
case HashAlgorithmTags.SHA512:
return new SHA512Digest();
case HashAlgorithmTags.MD2:
return new MD2Digest();
case HashAlgorithmTags.MD5:
return new MD5Digest();
case HashAlgorithmTags.RIPEMD160:
return new RIPEMD160Digest();
case HashAlgorithmTags.TIGER_192:
return new TigerDigest();
default:
throw new PGPException("cannot recognise digest");
}
}
示例7: doTest6
import org.bouncycastle.crypto.digests.RIPEMD160Digest; //导入依赖的package包/类
public void doTest6()
throws Exception
{
byte[] salt = Hex.decode("61DF870C4890FE85D6E3DD87C3DCE3723F91DB49");
RSAKeyParameters pubParameters = new RSAKeyParameters(false, mod6, pub6);
RSAKeyParameters privParameters = new RSAKeyParameters(true, mod6, pri6);
ParametersWithSalt sigParameters = new ParametersWithSalt(privParameters, salt);
RSAEngine rsa = new RSAEngine();
byte[] data;
//
// ISO 9796-2 - PSS Signing
//
ISO9796d2PSSSigner eng = new ISO9796d2PSSSigner(rsa, new RIPEMD160Digest(), 20, true);
eng.init(true, sigParameters);
data = eng.generateSignature();
if (eng.getRecoveredMessage().length != 0)
{
fail("failed zero check");
}
eng.init(false, pubParameters);
if (!isSameAs(sig6, 1, data))
{
fail("failed ISO9796-2 generation Test 6");
}
if (!eng.verifySignature(data))
{
fail("failed ISO9796-2 verify Test 6");
}
}
示例8: doTest8
import org.bouncycastle.crypto.digests.RIPEMD160Digest; //导入依赖的package包/类
public void doTest8()
throws Exception
{
byte[] salt = Hex.decode("78E293203CBA1B7F92F05F4D171FF8CA3E738FF8");
RSAKeyParameters pubParameters = new RSAKeyParameters(false, mod6, pub6);
RSAKeyParameters privParameters = new RSAKeyParameters(true, mod6, pri6);
ParametersWithSalt sigParameters = new ParametersWithSalt(privParameters, salt);
RSAEngine rsa = new RSAEngine();
byte[] data;
//
// ISO 9796-2 - PSS Signing
//
ISO9796d2PSSSigner eng = new ISO9796d2PSSSigner(rsa, new RIPEMD160Digest(), 20, false);
eng.init(true, sigParameters);
eng.update(msg8[0]);
eng.update(msg8, 1, msg8.length - 1);
data = eng.generateSignature();
eng.init(false, pubParameters);
if (!isSameAs(sig8, 0, data))
{
fail("failed ISO9796-2 generation Test 8");
}
eng.update(msg8[0]);
eng.update(msg8, 1, msg8.length - 1);
if (!eng.verifySignature(sig8))
{
fail("failed ISO9796-2 verify Test 8");
}
}
示例9: initDigesters
import org.bouncycastle.crypto.digests.RIPEMD160Digest; //导入依赖的package包/类
private static void initDigesters() {
digesters.put("Blake2b", Blake2bDigest.class);
digesters.put("GOST3411", GOST3411Digest.class);
digesters.put("Keccak", KeccakDigest.class);
digesters.put("MD2", MD2Digest.class);
digesters.put("MD4", MD4Digest.class);
digesters.put("MD5", MD5Digest.class);
digesters.put("RIPEMD128", RIPEMD128Digest.class);
digesters.put("RIPEMD160", RIPEMD160Digest.class);
digesters.put("RIPEMD256", RIPEMD256Digest.class);
digesters.put("RIPEMD320", RIPEMD320Digest.class);
digesters.put("SHA1", SHA1Digest.class);
digesters.put("SHA224", SHA224Digest.class);
digesters.put("SHA256", SHA256Digest.class);
digesters.put("SHA384", SHA384Digest.class);
digesters.put("SHA3-512", SHA3Digest.class);
digesters.put("SHA3-256", SHA3Digest.class);
digesters.put("SHA3-224", SHA3Digest.class);
digesters.put("SHA3-384", SHA3Digest.class);
digesters.put("SHA512", SHA512Digest.class);
digesters.put("SHAKE-128", SHAKEDigest.class);
digesters.put("SHAKE-256", SHAKEDigest.class);
digesters.put("Skein256", SkeinDigest.class);
digesters.put("Skein512", SkeinDigest.class);
digesters.put("Skein1024", SkeinDigest.class);
digesters.put("SM3", SM3Digest.class);
digesters.put("Tiger", TigerDigest.class);
digesters.put("Whirlpool", WhirlpoolDigest.class);
}
示例10: RIPEMD160
import org.bouncycastle.crypto.digests.RIPEMD160Digest; //导入依赖的package包/类
/********
* This method does all the RipeMD 160 hashing function, and after that hash has taken place, it prepends the version
* byte to the beginning of the Byte array
* @param tobeHashed - Byte Array of the public key after a SHA-256 hash
* @return - Byte Array after the RipeMD 160 hash function
*/
private byte[] RIPEMD160(byte[] tobeHashed){
RIPEMD160Digest digester = new RIPEMD160Digest();
byte[] retValue=new byte[digester.getDigestSize()];
digester.update(tobeHashed, 0, tobeHashed.length);
digester.doFinal(retValue, 0);
byte[] version = new byte[]{0x00};
return concateByteArray(version,retValue);
}
示例11: calculateBitcoinAddress
import org.bouncycastle.crypto.digests.RIPEMD160Digest; //导入依赖的package包/类
/**
* Calculates the bitcoinaddress for the given byte array containing the public key and returns
* it
* as a String.
*
* @param publicKey A byte array containing the public key to calulcate the address for
* @return The Bitcoin address as a Base58 encoded string
*/
public static String calculateBitcoinAddress(byte[] publicKey) {
RIPEMD160Digest ripemd160 = new RIPEMD160Digest();
MessageDigest sha256;
try {
sha256 = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
byte[] sha256Hash = sha256.digest(publicKey);
byte[] ripemdHash = new byte[ripemd160.getDigestSize() + 1];
ripemd160.update(sha256Hash, 0, sha256Hash.length);
ripemd160.doFinal(ripemdHash, 1);
// Set version byte
ripemdHash[0] = 0;
sha256Hash = sha256.digest(ripemdHash);
sha256Hash = sha256.digest(sha256Hash);
byte[] addressBytes = new byte[ripemdHash.length + 4];
System.arraycopy(ripemdHash, 0, addressBytes, 0, ripemdHash.length);
System.arraycopy(sha256Hash, 0, addressBytes, (ripemdHash.length), 4);
return Base58.encode(addressBytes);
}
示例12: getHashFromSignedTransaction
import org.bouncycastle.crypto.digests.RIPEMD160Digest; //导入依赖的package包/类
/**
* Get the hash of a signed transactoin
*
* @param signedTransaction the signed transaction as byte array
* @return the hash as String (Base58 encoded)
*/
public static String getHashFromSignedTransaction(byte[] signedTransaction) {
// TODO implemnt it correctly
RIPEMD160Digest ripemd160 = new RIPEMD160Digest();
MessageDigest sha256;
try {
sha256 = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
byte[] sha256Hash = sha256.digest(signedTransaction);
byte[] ripemdHash = new byte[ripemd160.getDigestSize() + 1];
ripemd160.update(sha256Hash, 0, sha256Hash.length);
ripemd160.doFinal(ripemdHash, 1);
// Set version byte
ripemdHash[0] = 0;
sha256Hash = sha256.digest(ripemdHash);
sha256Hash = sha256.digest(sha256Hash);
byte[] addressBytes = new byte[ripemdHash.length + 4];
System.arraycopy(ripemdHash, 0, addressBytes, 0, ripemdHash.length);
System.arraycopy(sha256Hash, 0, addressBytes, (ripemdHash.length), 4);
return Base58.encode(addressBytes);
}
示例13: createFromUserId
import org.bouncycastle.crypto.digests.RIPEMD160Digest; //导入依赖的package包/类
public static PgpUserIdNameHash createFromUserId(final String userId) {
assertNotNull(userId, "userId");
final RIPEMD160Digest digest = new RIPEMD160Digest();
byte[] userIdBytes = userId.getBytes(StandardCharsets.UTF_8); // TODO is this correct?! really UTF-8?! check with my own name! ;-)
digest.update(userIdBytes, 0, userIdBytes.length);
final byte[] out = new byte[digest.getDigestSize()];
digest.doFinal(out, 0);
return new PgpUserIdNameHash(out);
}
示例14: hash160
import org.bouncycastle.crypto.digests.RIPEMD160Digest; //导入依赖的package包/类
/**
* Calculate the RIPEMD160 hash of the input
*
* @param input The byte array to be hashed
* @return The hashed result
*/
public static byte[] hash160(byte[] input) {
byte[] out = new byte[20];
RIPEMD160Digest rDigest = new RIPEMD160Digest();
rDigest.update(input, 0, input.length);
rDigest.doFinal(out, 0);
return out;
}
示例15: sha256Hash160
import org.bouncycastle.crypto.digests.RIPEMD160Digest; //导入依赖的package包/类
/**
* Calculate RIPEMD160(SHA256(input)). This is used in Address calculations.
*
* @param input The byte array to be hashed
* @return The hashed result
*/
public static byte[] sha256Hash160(byte[] input) {
byte[] out = new byte[20];
synchronized(digest) {
digest.reset();
byte[] sha256 = digest.digest(input);
RIPEMD160Digest rDigest = new RIPEMD160Digest();
rDigest.update(sha256, 0, sha256.length);
rDigest.doFinal(out, 0);
}
return out;
}