当前位置: 首页>>代码示例>>Java>>正文


Java MessageDigest.reset方法代码示例

本文整理汇总了Java中java.security.MessageDigest.reset方法的典型用法代码示例。如果您正苦于以下问题:Java MessageDigest.reset方法的具体用法?Java MessageDigest.reset怎么用?Java MessageDigest.reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.security.MessageDigest的用法示例。


在下文中一共展示了MessageDigest.reset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: scramble411

import java.security.MessageDigest; //导入方法依赖的package包/类
public static byte[] scramble411(String password, String seed, String passwordEncoding) throws NoSuchAlgorithmException, UnsupportedEncodingException {
    MessageDigest md = MessageDigest.getInstance("SHA-1");

    byte[] passwordHashStage1 = md.digest((passwordEncoding == null || passwordEncoding.length() == 0) ? StringUtils.getBytes(password)
            : StringUtils.getBytes(password, passwordEncoding));
    md.reset();

    byte[] passwordHashStage2 = md.digest(passwordHashStage1);
    md.reset();

    byte[] seedAsBytes = StringUtils.getBytes(seed, "ASCII"); // for debugging
    md.update(seedAsBytes);
    md.update(passwordHashStage2);

    byte[] toBeXord = md.digest();

    int numToXor = toBeXord.length;

    for (int i = 0; i < numToXor; i++) {
        toBeXord[i] = (byte) (toBeXord[i] ^ passwordHashStage1[i]);
    }

    return toBeXord;
}
 
开发者ID:rafallis,项目名称:BibliotecaPS,代码行数:25,代码来源:Security.java

示例2: tryHashStringSha256

import java.security.MessageDigest; //导入方法依赖的package包/类
/**
 * Get a SHA-256 hash of the input string if the algorithm is available. If the algorithm is
 * unavailable, return empty string.
 *
 * @param input the string to hash.
 * @return a SHA-256 hash of the input or the input if SHA-256 is not available (should not happen).
 */
private static String tryHashStringSha256(Context context, String input) {
    String salt = createSalt(context);
    try {
        // Get a Sha256 digest
        MessageDigest hash = MessageDigest.getInstance("SHA-256");
        hash.reset();
        hash.update(input.getBytes());
        hash.update(salt.getBytes());
        byte[] hashedBytes = hash.digest();

        return bytesToHex(hashedBytes);
    } catch (NoSuchAlgorithmException e) {
        // All android devices should support SHA256, but if unavailable return input
        return input;
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:24,代码来源:CrashConstants.java

示例3: getSeed

import java.security.MessageDigest; //导入方法依赖的package包/类
/**
 * Generates a new random seed.
 *
 * @param streamId a string identifying the stream of random numbers
 * @param masterSeed higher level master random seed
 * @return the random seed. Different (streamId, masterSeed) pairs result in
 *         (vastly) different random seeds.
 */   
public static long getSeed(String streamId, long masterSeed) {
  MessageDigest md5 = md5Holder.get();
  md5.reset();
  //'/' : make sure that we don't get the same str from ('11',0) and ('1',10)
  // We could have fed the bytes of masterSeed one by one to md5.update()
  // instead
  String str = streamId + '/' + masterSeed;
  byte[] digest = md5.digest(str.getBytes(UTF_8));
  // Create a long from the first 8 bytes of the digest
  // This is fine as MD5 has the avalanche property.
  // Paranoids could have XOR folded the other 8 bytes in too. 
  long seed = 0;
  for (int i=0; i<8; i++) {
    seed = (seed<<8) + ((int)digest[i]+128);
  }
  return seed;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:26,代码来源:RandomSeedGenerator.java

示例4: Sign

import java.security.MessageDigest; //导入方法依赖的package包/类
public static String Sign(ApsvOrder order, String secret) {
    String[] data = new String[]{order.time, order.tradeNo, Float.toString(order.amount), order.status, secret};
    String dataStr = String.join("|", data);
    try {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.reset();
        md5.update(dataStr.getBytes(Charset.forName("UTF-8")));
        byte[] dataBytes = md5.digest();
        StringBuffer buffer = new StringBuffer();
        for (int i=0; i<dataBytes.length; i++) {
            if (Integer.toHexString(0xFF & dataBytes[i]).length() == 1)
                buffer.append("0").append(
                        Integer.toHexString(0xFF & dataBytes[i]));
            else
                buffer.append(Integer.toHexString(0xFF & dataBytes[i]));
        }
        return buffer.toString();
    } catch (NoSuchAlgorithmException e) {
        return "";
    }
}
 
开发者ID:thundernet8,项目名称:AlipayOrdersSupervisor-GUI,代码行数:22,代码来源:Order.java

示例5: calcClassSign

import java.security.MessageDigest; //导入方法依赖的package包/类
private static String calcClassSign(String name) {
    try {
        Class<?> clazz = Class.forName(name);

        ByteArrayOutputStream result = new ByteArrayOutputStream();
        ObjectOutputStream outputStream = new ObjectOutputStream(result);
        outputStream.writeObject(clazz);
        outputStream.close();

        MessageDigest crypt = MessageDigest.getInstance("SHA-1");
        crypt.reset();
        crypt.update(result.toByteArray());

        return new BigInteger(1, crypt.digest()).toString(16);
    } catch (Exception e) {
        throw new IllegalStateException("Can't calculate sign of " + name, e);
    }
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:19,代码来源:RedissonSortedSet.java

示例6: getFingerprint

import java.security.MessageDigest; //导入方法依赖的package包/类
/**
 * 返回指定Apk文件的指纹信息
 * 
 * @param context
 * @param archiveFilePath
 * @param algorithm MD5 or SHA1
 * @return
 */
public static String getFingerprint(Context context, String archiveFilePath, String algorithm) {
	try {
		PackageInfo packageInfo = context.getPackageManager().getPackageArchiveInfo(archiveFilePath,
				PackageManager.GET_SIGNATURES);
		if (packageInfo == null) {
			return null;
		}
		Signature[] signs = packageInfo.signatures;
		MessageDigest md = MessageDigest.getInstance(algorithm);
		md.reset();
		md.update(signs[0].toByteArray());
		byte[] dataHash = md.digest();
		return bytes2HexString(dataHash);
	} catch (Exception e) {
		e.printStackTrace();
	}

	return null;
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:28,代码来源:ApkSignUtils.java

示例7: encoderMD5

import java.security.MessageDigest; //导入方法依赖的package包/类
/**
 * 加密 MD5 
 * 
 * @param strInput
 *            输入字符串
 * @return String
 * @throws Exception
 */
public final static String encoderMD5(String strInput) {
	if(strInput == null){
		return null;
	}
	MessageDigest messageDigest = null;
	try {
		messageDigest = MessageDigest.getInstance("MD5");
		messageDigest.reset();
		messageDigest.update(strInput.getBytes("UTF-8"));
	} catch (Exception ex) {
		logger.error("create MD5 error!",ex);
	}

	byte[] byteArray = messageDigest.digest();
	StringBuffer md5StrBuff = new StringBuffer();
	for (byte b : byteArray) {
		if (Integer.toHexString(0xFF & b).length() == 1) {
			md5StrBuff.append("0").append(Integer.toHexString(0xFF & b));
		} else {
			md5StrBuff.append(Integer.toHexString(0xFF & b));
		}
	}
	return md5StrBuff.toString();
}
 
开发者ID:dimensoft,项目名称:improved-journey,代码行数:33,代码来源:SecurityUtil.java

示例8: computeRev13Response

import java.security.MessageDigest; //导入方法依赖的package包/类
static String computeRev13Response(String key) throws IOException {
	key = key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
	MessageDigest md = null;
	try {
		md = MessageDigest.getInstance("SHA1");
		md.reset();
	} catch (NoSuchAlgorithmException ex) {
		// log.log(Level.SEVERE, "MD5 Algorithm not found", ex);
		ex.printStackTrace();
	}
	byte[] digest = md.digest(key.getBytes());
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	return new String(Base64Coder.encode(digest));
	
}
 
开发者ID:YunlongYang,项目名称:LightSIP,代码行数:16,代码来源:WebSocketHttpHandshake.java

示例9: decryptKey

import java.security.MessageDigest; //导入方法依赖的package包/类
private static byte[] decryptKey(byte[] encryptedPKI, byte[] passwd)
    throws UnrecoverableKeyException
{
    try
    {
        EncryptedPrivateKeyInfo epki =
            new EncryptedPrivateKeyInfo(encryptedPKI);
        byte[] encr = epki.getEncryptedData();
        byte[] keystream = new byte[20];
        System.arraycopy(encr, 0, keystream, 0, 20);
        byte[] check = new byte[20];
        System.arraycopy(encr, encr.length-20, check, 0, 20);
        byte[] key = new byte[encr.length - 40];
        MessageDigest sha = MessageDigest.getInstance("SHA1");
        int count = 0;
        while (count < key.length)
        {
            sha.reset();
            sha.update(passwd);
            sha.update(keystream);
            sha.digest(keystream, 0, keystream.length);
            for (int i = 0; i < keystream.length && count < key.length; i++)
            {
                key[count] = (byte) (keystream[i] ^ encr[count+20]);
                count++;
            }
        }
        sha.reset();
        sha.update(passwd);
        sha.update(key);
        if (!MessageDigest.isEqual(check, sha.digest()))
            throw new UnrecoverableKeyException("checksum mismatch");
        return key;
    }
    catch (Exception x)
    {
        throw new UnrecoverableKeyException(x.getMessage());
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:40,代码来源:JKS.java

示例10: encryptKey

import java.security.MessageDigest; //导入方法依赖的package包/类
private static byte[] encryptKey(Key key, byte[] passwd)
    throws KeyStoreException
{
    try
    {
        MessageDigest sha = MessageDigest.getInstance("SHA1");
        SecureRandom rand = SecureRandom.getInstance("SHA1PRNG");
        byte[] k = key.getEncoded();
        byte[] encrypted = new byte[k.length + 40];
        byte[] keystream = rand.getSeed(20);
        System.arraycopy(keystream, 0, encrypted, 0, 20);
        int count = 0;
        while (count < k.length)
        {
            sha.reset();
            sha.update(passwd);
            sha.update(keystream);
            sha.digest(keystream, 0, keystream.length);
            for (int i = 0; i < keystream.length && count < k.length; i++)
            {
                encrypted[count+20] = (byte) (keystream[i] ^ k[count]);
                count++;
            }
        }
        sha.reset();
        sha.update(passwd);
        sha.update(k);
        sha.digest(encrypted, encrypted.length - 20, 20);
        // 1.3.6.1.4.1.42.2.17.1.1 is Sun's private OID for this
        // encryption algorithm.
        return new EncryptedPrivateKeyInfo("1.3.6.1.4.1.42.2.17.1.1",
            encrypted).getEncoded();
    }
    catch (Exception x)
    {
        throw new KeyStoreException(x.getMessage());
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:39,代码来源:JKS.java

示例11: verify

import java.security.MessageDigest; //导入方法依赖的package包/类
static boolean verify(String tag, BigInteger modulus, String data, String signature) {
    if (TextUtils.isEmpty(data) || TextUtils.isEmpty(signature)) {
        return false;
    }
    BigInteger exponent = BigInteger.valueOf(0x10001);
    try {
        MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
        sha1.update(data.getBytes());
        byte[] digest = sha1.digest();
        byte[] key = Base64.decode(signature, Base64.DEFAULT);
        byte[] sign = new BigInteger(1, key).modPow(exponent, modulus).toByteArray();
        for (int i = digest.length - 1, j = sign.length - 1; i >= 0; --i, --j) {
            sign[j] ^= digest[i];
        }
        sha1.reset();
        sha1.update(sign);
        digest = sha1.digest();
        for (int i = digest.length - 1; i >= 0; --i) {
            if (digest[i] != SHA_EXPECTED[i]) {
                return false;
            }
        }
        return true;
    } catch (IllegalArgumentException | GeneralSecurityException e) {
        Log.d(tag, "Can't verify");
    }
    return false;
}
 
开发者ID:brevent,项目名称:Brevent,代码行数:29,代码来源:PlayServiceConnection.java

示例12: streamDecrypt

import java.security.MessageDigest; //导入方法依赖的package包/类
public static Object streamDecrypt(byte[] data, SecretKey key,
    MessageDigest digest) throws Exception {

    Cipher decCipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
    decCipher.init(Cipher.DECRYPT_MODE, key);
    digest.reset();
    try (ByteArrayInputStream bis = new ByteArrayInputStream(data);
        DigestInputStream dis = new DigestInputStream(bis, digest);
        CipherInputStream cis = new CipherInputStream(dis, decCipher)) {

        try (ObjectInputStream ois = new ObjectInputStream(cis)) {
            return ois.readObject();
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:CipherStreamClose.java

示例13: getSHA1

import java.security.MessageDigest; //导入方法依赖的package包/类
public static String getSHA1(String toHash) {
	MessageDigest md = null;
	try {
		md = MessageDigest.getInstance("SHA1");
		md.reset();
		md.update(toHash.getBytes("UTF-8"));
	} catch (Exception ignored) {
		return "";
	}

	return String.format("%1$040x", new Object[] { new BigInteger(1, md.digest()) });
}
 
开发者ID:DivergenceBot,项目名称:UpdateBuilder,代码行数:13,代码来源:SHA1Util.java

示例14: toMd5

import java.security.MessageDigest; //导入方法依赖的package包/类
public static String toMd5(String md5Str) {
    String result = "";
    try {
        MessageDigest algorithm = MessageDigest.getInstance(CommonUtils.MD5_INSTANCE);
        algorithm.reset();
        algorithm.update(md5Str.getBytes("utf-8"));
        result = toHexString(algorithm.digest());
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    } catch (UnsupportedEncodingException e2) {
        e2.printStackTrace();
    }
    return result;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:15,代码来源:MD5.java

示例15: generateKey

import java.security.MessageDigest; //导入方法依赖的package包/类
private static byte[] generateKey() throws Exception {
	String random = UUID.randomUUID().toString();
	MessageDigest algorithm = MessageDigest.getInstance("MD5");
	algorithm.reset();
	algorithm.update(random.getBytes());
	byte[] messageDigest = algorithm.digest();
	return Base64.getEncoder().encode(messageDigest);
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:9,代码来源:TestJwt.java


注:本文中的java.security.MessageDigest.reset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。