當前位置: 首頁>>代碼示例>>Java>>正文


Java MessageDigest.update方法代碼示例

本文整理匯總了Java中java.security.MessageDigest.update方法的典型用法代碼示例。如果您正苦於以下問題:Java MessageDigest.update方法的具體用法?Java MessageDigest.update怎麽用?Java MessageDigest.update使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.security.MessageDigest的用法示例。


在下文中一共展示了MessageDigest.update方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: signWithoutSettingParameterOrder

import java.security.MessageDigest; //導入方法依賴的package包/類
private byte[] signWithoutSettingParameterOrder(Map<String, String> map, HttpEntity entity){
	// TODO signature length should be constant. currently signature length is proportional to number of parameters.
	ByteArrayOutputStream signature = new ByteArrayOutputStream();
	try{
		MessageDigest md = MessageDigest.getInstance(HASHING_ALGORITHM);
		for(Entry<String,String> entry : map.entrySet()){
			String parameterName = entry.getKey();
			if(parameterName.equals(SecurityParameters.SIGNATURE) || "submitAction".equals(parameterName)){
				continue;
			}
			String value = entry.getValue();
			String keyValue = parameterName.concat(value == null ? "" : value);
			String keyValueSalt = keyValue.concat(salt);
			md.update(keyValueSalt.getBytes(StandardCharsets.UTF_8));
			signature.write(md.digest());
		}

		if(entity != null){
			byte[] bytes = EntityUtils.toByteArray(entity);
			md.update(bytes);
			md.update(salt.getBytes(StandardCharsets.UTF_8));
			signature.write(md.digest());
		}
	}catch(IOException | NoSuchAlgorithmException e){
		throw new RuntimeException(e);
	}
	return signature.toByteArray();
}
 
開發者ID:hotpads,項目名稱:datarouter,代碼行數:29,代碼來源:DefaultSignatureValidator.java

示例2: md5action

import java.security.MessageDigest; //導入方法依賴的package包/類
private void md5action(String s) {
	try {
		MessageDigest md = MessageDigest.getInstance("MD5");
		md.update(s.getBytes());
		byte[] buff = md.digest();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < buff.length; i++) {
			sb.append(Integer.toString((buff[i] & 0xff) + 0x100, 16).substring(1));
		}
		stringdata = sb.toString();
		bytedata = new byte[] {};
	} catch (NoSuchAlgorithmException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
開發者ID:biancso,項目名稱:Mevius-IO,代碼行數:17,代碼來源:MeviusCipher.java

示例3: MD5

import java.security.MessageDigest; //導入方法依賴的package包/類
public final static String MD5(String s) {
    char hexDigits[]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
    try {
        byte[] btInput = s.getBytes();
        // 獲得MD5摘要算法的 MessageDigest 對象
        MessageDigest mdInst = MessageDigest.getInstance("MD5");
        // 使用指定的字節更新摘要
        mdInst.update(btInput);
        // 獲得密文
        byte[] md = mdInst.digest();
        // 把密文轉換成十六進製的字符串形式
        int j = md.length;
        char str[] = new char[j * 2];
        int k = 0;
        for (int i = 0; i < j; i++) {
            byte byte0 = md[i];
            str[k++] = hexDigits[byte0 >>> 4 & 0xf];
            str[k++] = hexDigits[byte0 & 0xf];
        }
        return new String(str);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
開發者ID:GroupControlDroid,項目名稱:GroupControlDroidClient,代碼行數:26,代碼來源:MD5Util.java

示例4: decrypt

import java.security.MessageDigest; //導入方法依賴的package包/類
public static byte[] decrypt(byte[] encryptedIvTextBytes, String key) throws Exception {
    byte ivSize = 16;
    byte keySize = 16;
    byte[] iv = new byte[ivSize];
    System.arraycopy(encryptedIvTextBytes, 0, iv, 0, iv.length);
    IvParameterSpec ivParameterSpec = new IvParameterSpec(iv);
    int encryptedSize = encryptedIvTextBytes.length - ivSize;
    byte[] encryptedBytes = new byte[encryptedSize];
    System.arraycopy(encryptedIvTextBytes, ivSize, encryptedBytes, 0, encryptedSize);
    byte[] keyBytes = new byte[keySize];
    MessageDigest md = MessageDigest.getInstance("SHA-256");
    md.update(key.getBytes());
    System.arraycopy(md.digest(), 0, keyBytes, 0, keyBytes.length);
    SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "AES");
    Cipher cipherDecrypt = Cipher.getInstance("AES/CBC/PKCS5Padding");
    cipherDecrypt.init(2, secretKeySpec, ivParameterSpec);
    byte[] decrypted = cipherDecrypt.doFinal(encryptedBytes);
    return decrypted;
}
 
開發者ID:toannhu,項目名稱:AES-with-CBC,代碼行數:20,代碼來源:AES.java

示例5: keyHash

import java.security.MessageDigest; //導入方法依賴的package包/類
public static void keyHash(Context context){

        // Add code to print out the key hash
        try {
            PackageInfo info = context.getPackageManager().getPackageInfo(
                    "barreto.alessandro.feedlist",
                    PackageManager.GET_SIGNATURES);
            for (Signature signature : info.signatures) {
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
            }
        } catch (PackageManager.NameNotFoundException | NoSuchAlgorithmException ignored) {
            Log.e("Facebook",ignored.getMessage());
        }

    }
 
開發者ID:AleBarreto,項目名稱:FeedFire,代碼行數:18,代碼來源:FacebookSign.java

示例6: computeSHA1

import java.security.MessageDigest; //導入方法依賴的package包/類
public static byte[] computeSHA1(ByteBuffer convertme, int offset, int len) {
    int oldp = convertme.position();
    int oldl = convertme.limit();
    try {
        MessageDigest md = MessageDigest.getInstance("SHA-1");
        convertme.position(offset);
        convertme.limit(len);
        md.update(convertme);
        return md.digest();
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    } finally {
        convertme.limit(oldl);
        convertme.position(oldp);
    }
    return new byte[20];
}
 
開發者ID:pooyafaroka,項目名稱:PlusGram,代碼行數:18,代碼來源:Utilities.java

示例7: hashFile

import java.security.MessageDigest; //導入方法依賴的package包/類
public static String hashFile(FileHandle fileHandle) throws Exception {
  InputStream inputStream = fileHandle.read();
  try {
    MessageDigest digest = MessageDigest.getInstance("SHA-256");

    byte[] bytesBuffer = new byte[1024];
    int bytesRead;
int n =inputStream.read(bytesBuffer);
    while ((bytesRead = n) != -1) {
      digest.update(bytesBuffer, 0, bytesRead);
      n=inputStream.read(bytesBuffer);
    }

    byte[] hashedBytes = digest.digest();
    return convertByteArrayToHexString(hashedBytes);
  } catch (IOException ex) {
    throw new CubesException("Could not generate hash from file " + fileHandle.path(), ex);
  } finally {
    StreamUtils.closeQuietly(inputStream);
  }
}
 
開發者ID:RedTroop,項目名稱:Cubes_2,代碼行數:22,代碼來源:AndroidModLoader.java

示例8: digest

import java.security.MessageDigest; //導入方法依賴的package包/類
private static String digest(InputStream input, String algorithm) throws IOException {
	try {
		MessageDigest messageDigest = MessageDigest.getInstance(algorithm);
		int bufferLength = 1024;
		byte[] buffer = new byte[bufferLength];
		int read = input.read(buffer, 0, bufferLength);

		while (read > -1) {
			messageDigest.update(buffer, 0, read);
			read = input.read(buffer, 0, bufferLength);
		}

		return EncodeUtils.encodeHex(messageDigest.digest());

	} catch (GeneralSecurityException e) {
		throw ExceptionUtils.unchecked(e);
	}
}
 
開發者ID:wkeyuan,項目名稱:DWSurvey,代碼行數:19,代碼來源:DigestUtils.java

示例9: encryption

import java.security.MessageDigest; //導入方法依賴的package包/類
/**
 *
 * @param plainText 明文
 * @return 32位密文
 */
public static String encryption(String plainText) {
    String re_md5 = new String();
    try {
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(plainText.getBytes());
        byte b[] = md.digest();
        int i;
        StringBuffer buf = new StringBuffer("");
        for (int offset = 0; offset < b.length; offset++) {
            i = b[offset];
            if (i < 0)
                i += 256;
            if (i < 16)
                buf.append("0");
            buf.append(Integer.toHexString(i));
        }
        re_md5 = buf.toString();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    return re_md5;
}
 
開發者ID:dragon-yuan,項目名稱:Ins_fb_pictureSpider_WEB,代碼行數:28,代碼來源:MD5.java

示例10: getMD5String

import java.security.MessageDigest; //導入方法依賴的package包/類
public static String getMD5String(String key) {
    String cacheKey;
    try {
        final MessageDigest mDigest = MessageDigest.getInstance("MD5");
        mDigest.update(key.getBytes());
        cacheKey = bytesToHexString(mDigest.digest());
    } catch (NoSuchAlgorithmException e) {
        cacheKey = String.valueOf(key.hashCode());
    }
    return cacheKey;
}
 
開發者ID:InnoFang,項目名稱:Android-Code-Demos,代碼行數:12,代碼來源:DiskCacheUtil.java

示例11: MD5

import java.security.MessageDigest; //導入方法依賴的package包/類
public static final byte[] MD5(InputStream in) throws NoSuchAlgorithmException, IOException {
    MessageDigest digest = MessageDigest.getInstance("MD5");
    byte buffer[] = new byte[4096];
    int rc = 0;
    while ((rc = in.read(buffer)) >= 0) {
        if (rc > 0) {
            digest.update(buffer, 0, rc);
        }
    }
    return digest.digest();
}
 
開發者ID:wangyupeng1-iri,項目名稱:springreplugin,代碼行數:12,代碼來源:SecurityUtil.java

示例12: validateSignature

import java.security.MessageDigest; //導入方法依賴的package包/類
@SuppressLint("PackageManagerGetSignatures")
private static EvernoteInstallStatus validateSignature(PackageManager packageManager) {
    MessageDigest digest = getSha256Digest();
    if (digest == null) {
        // can't compare signatures
        return EvernoteInstallStatus.NOT_INSTALLED;
    }

    PackageInfo packageInfo;
    try {
        packageInfo = packageManager.getPackageInfo(PACKAGE_NAME, PackageManager.GET_SIGNATURES);
    } catch (PackageManager.NameNotFoundException e) {
        return EvernoteInstallStatus.NOT_INSTALLED;
    }

    if (packageInfo.signatures == null || packageInfo.signatures.length == 0) {
        // must have at least one signature
        return EvernoteInstallStatus.NOT_INSTALLED;
    }

    // check all signatures
    for (Signature signature : packageInfo.signatures) {
        digest.update(signature.toByteArray());
        String appSignature = encodeBase64(digest.digest());
        if (EVERNOTE_SIGNATURE.equals(appSignature)) {
            return EvernoteInstallStatus.INSTALLED;
        }
    }
    return EvernoteInstallStatus.NOT_INSTALLED;
}
 
開發者ID:fivef,項目名稱:add_to_evernote_note,代碼行數:31,代碼來源:EvernoteUtil.java

示例13: a

import java.security.MessageDigest; //導入方法依賴的package包/類
private static boolean a(Context context) {
    try {
        PackageInfo packageInfo = context.getPackageManager().getPackageInfo("com.tencent" +
                ".mtt", 64);
        String str = packageInfo.versionName;
        if (SystemUtils.compareVersion(str, "4.3") < 0 || str.startsWith("4.4")) {
            return false;
        }
        Signature[] signatureArr = packageInfo.signatures;
        if (signatureArr == null) {
            return false;
        }
        try {
            MessageDigest instance = MessageDigest.getInstance(Coder.KEY_MD5);
            instance.update(signatureArr[0].toByteArray());
            String toHexString = toHexString(instance.digest());
            instance.reset();
            str = "d8391a394d4a179e6fe7bdb8a301258b";
            if (toHexString.equals("d8391a394d4a179e6fe7bdb8a301258b")) {
                return true;
            }
            return false;
        } catch (NoSuchAlgorithmException e) {
            f.e(a, "isQQBrowerAvailable has exception: " + e.getMessage());
            return false;
        }
    } catch (NameNotFoundException e2) {
        return false;
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:31,代碼來源:Util.java

示例14: hashKeyForDisk

import java.security.MessageDigest; //導入方法依賴的package包/類
/**
 * 傳入緩存的key值,以得到相應的MD5值
 *
 * @param key
 * @return
 */
public static String hashKeyForDisk(String key) {
    String cacheKey;
    try {
        final MessageDigest mDigest = MessageDigest.getInstance("MD5");
        mDigest.update(key.getBytes());
        cacheKey = bytesToHexString(mDigest.digest());
    } catch (NoSuchAlgorithmException e) {
        cacheKey = String.valueOf(key.hashCode());
    }
    return cacheKey;
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:18,代碼來源:DiskLruCacheUtil.java

示例15: md5Encryp

import java.security.MessageDigest; //導入方法依賴的package包/類
/**
    * 獲取一個字符串的MD5
    * @param msg
    * @return 加密後的MD5字符串
    * @throws NoSuchAlgorithmException 
    */
   public static String md5Encryp(String msg) throws NoSuchAlgorithmException 
{
       // 生成一個MD5加密計算摘要
       MessageDigest md = MessageDigest.getInstance("MD5");
       // 計算md5函數
       md.update(msg.getBytes());
       return new BigInteger(1, md.digest()).toString(16);
   }
 
開發者ID:cendi2005,項目名稱:jshERP,代碼行數:15,代碼來源:Tools.java


注:本文中的java.security.MessageDigest.update方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。