當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。