本文整理匯總了Java中java.security.NoSuchAlgorithmException.printStackTrace方法的典型用法代碼示例。如果您正苦於以下問題:Java NoSuchAlgorithmException.printStackTrace方法的具體用法?Java NoSuchAlgorithmException.printStackTrace怎麽用?Java NoSuchAlgorithmException.printStackTrace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.security.NoSuchAlgorithmException
的用法示例。
在下文中一共展示了NoSuchAlgorithmException.printStackTrace方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: md5
import java.security.NoSuchAlgorithmException; //導入方法依賴的package包/類
public String md5(String s) {
try {
// Create MD5 Hash
MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
digest.update(s.getBytes());
byte messageDigest[] = digest.digest();
// Create Hex String
StringBuffer hexString = new StringBuffer();
for (int i=0; i<messageDigest.length; i++)
hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
示例2: checkSignature
import java.security.NoSuchAlgorithmException; //導入方法依賴的package包/類
/**
* 驗證簽名
*
* @param signature
* @param timestamp
* @param nonce
* @return
*/
public static boolean checkSignature(String signature, String timestamp,
String nonce) {
String[] arr = new String[] { token, timestamp, nonce };
// 將token、timestamp、nonce三個參數進行字典序排序
Arrays.sort(arr);
StringBuilder content = new StringBuilder();
for (int i = 0; i < arr.length; i++) {
content.append(arr[i]);
}
MessageDigest md = null;
String tmpStr = null;
try {
md = MessageDigest.getInstance("SHA-1");
// 將三個參數字符串拚接成一個字符串進行sha1加密
byte[] digest = md.digest(content.toString().getBytes());
tmpStr = byteToStr(digest);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
content = null;
// 將sha1加密後的字符串可與signature對比,標識該請求來源於微信
return tmpStr != null ? tmpStr.equals(signature.toUpperCase()) : false;
}
示例3: encryptSHAWithBuffer
import java.security.NoSuchAlgorithmException; //導入方法依賴的package包/類
/**
* SHA-512 加密
* StringBuffer支持並發操作,線性安全的,適合多線程中使用。
*
* @param str
* @return
*/
public String encryptSHAWithBuffer(String str) {
if (str == null || str.length() == 0) {
return null;
}
StringBuffer buffer = new StringBuffer();
try {
MessageDigest digest = MessageDigest.getInstance("SHA-512");
digest.update(str.getBytes());
byte[] cipher = digest.digest();
for (byte b : cipher) {
String hexStr = Integer.toHexString(b & 0xff);
buffer.append(hexStr.length() == 1 ? "0" + hexStr : hexStr);
}
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return buffer.toString();
}
示例4: getHashedKey
import java.security.NoSuchAlgorithmException; //導入方法依賴的package包/類
public static synchronized String getHashedKey(String key){
try {
md = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
md.reset();
md.update((key).getBytes());
byte[] result = md.digest();
String hashedkey = "";
for(int i = 0; i < 16; i++){
int n = result[i] >> 4 & 0x0F;
hashedkey += String.format("%1s", Integer.toHexString(n));
n = result[i] & 0xF;
hashedkey += String.format("%1s", Integer.toHexString(n));
}
return hashedkey;
}
示例5: MD5
import java.security.NoSuchAlgorithmException; //導入方法依賴的package包/類
public static byte[] MD5(byte[] input) {
MessageDigest md = null;
try {
md = MessageDigest.getInstance(CommonUtils.MD5_INSTANCE);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
if (md == null) {
return null;
}
md.update(input);
return md.digest();
}
示例6: getMD5EncryptedString
import java.security.NoSuchAlgorithmException; //導入方法依賴的package包/類
public static String getMD5EncryptedString(String encTarget){
MessageDigest mdEnc = null;
try {
mdEnc = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
System.out.println("Exception while encrypting to md5");
e.printStackTrace();
} // Encryption algorithm
mdEnc.update(encTarget.getBytes(), 0, encTarget.length());
String md5 = new BigInteger(1, mdEnc.digest()).toString(16);
while ( md5.length() < 32 ) {
md5 = "0"+md5;
}
return md5;
}
示例7: encrypt
import java.security.NoSuchAlgorithmException; //導入方法依賴的package包/類
/**
* MD5加密
* @param str 待加密的字符串
* @return
*/
public static String encrypt(String str) {
String result = null;
try {
result = new String(str);
MessageDigest md = MessageDigest.getInstance("MD5");
result = byteToString(md.digest(str.getBytes()));
} catch (NoSuchAlgorithmException ex) {
ex.printStackTrace();
}
return result;
}
示例8: hashTemplate
import java.security.NoSuchAlgorithmException; //導入方法依賴的package包/類
/**
* hash加密模板
*
* @param data 數據
* @param algorithm 加密算法
* @return 密文字節數組
*/
private static byte[] hashTemplate(byte[] data, String algorithm) {
if (data == null || data.length <= 0) return null;
try {
MessageDigest md = MessageDigest.getInstance(algorithm);
md.update(data);
return md.digest();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
}
}
示例9: getMD5CodeByString
import java.security.NoSuchAlgorithmException; //導入方法依賴的package包/類
/**
* 獲取字符串的MD5
* @param str 源字符串
* @return
*/
public static String getMD5CodeByString(String str) {
try {
MessageDigest md;
md = MessageDigest.getInstance("MD5");
byte buf[] = md.digest(str.getBytes());
BASE64Encoder encoder = new BASE64Encoder();
return encoder.encode(buf);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
}
}
示例10: md5
import java.security.NoSuchAlgorithmException; //導入方法依賴的package包/類
public static String md5(String senha) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
BigInteger hash = new BigInteger(1, md.digest(senha.getBytes()));
return ((String) hash.toString(16));
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
示例11: encrypt
import java.security.NoSuchAlgorithmException; //導入方法依賴的package包/類
/**
* MD5加密
* @param str 待加密的字符串
* @param lowerCase 大小寫
* @return
*/
public static String encrypt(String str, boolean lowerCase) {
String result = null;
try {
result = str;
MessageDigest md = MessageDigest.getInstance("MD5");
result = byteToString(md.digest(str.getBytes()));
if (lowerCase) {
result = result.toLowerCase();
}
} catch (NoSuchAlgorithmException ex) {
ex.printStackTrace();
}
return result;
}
示例12: getMD5MessageDigest
import java.security.NoSuchAlgorithmException; //導入方法依賴的package包/類
private static MessageDigest getMD5MessageDigest(){
try {
return MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
Log.e(TAG, "Exception while getting digest", e);
return null;
}
}
示例13: calculateKSessionMac
import java.security.NoSuchAlgorithmException; //導入方法依賴的package包/類
public static byte[] calculateKSessionMac(byte[] kSessionSeed) {
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-1");
// KSession_MAC = the first 16 bytes of the SHA-1 hash over the concatenation of KSession_Seed ++ �00 00 00 02� with the parity bits adjusted
byte[] unadjustedParityKmac = Arrays.copyOfRange(md.digest(Bytes.concatenate(kSessionSeed, new byte[] {0x00, 0x00, 0x00, 0x02})), 0, 16);
byte[] kmac = adjustParityBits(unadjustedParityKmac);
return kmac;
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
示例14: hash
import java.security.NoSuchAlgorithmException; //導入方法依賴的package包/類
/**
* Returns a sha256 hash of the block.
* @param block - a proto Trustchain block
* @return the sha256 hash of the byte array of the block
*/
public static byte[] hash(MessageProto.TrustChainBlock block) {
MessageDigest md = null;
try {
md = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
//remove the signature (if there is any)
MessageProto.TrustChainBlock rawBlock = block.toBuilder().setSignature(EMPTY_SIG).build();
return md.digest(rawBlock.toByteArray());
}
示例15: toSHA1
import java.security.NoSuchAlgorithmException; //導入方法依賴的package包/類
/**
* Get SHA1 hash of a string
* @param convertme The string to convert
* @return SHA1 hash
*/
public static String toSHA1(String convertme)
{
byte[] data = convertme.getBytes();
MessageDigest md = null;
try {
md = MessageDigest.getInstance("SHA-1");
}
catch(NoSuchAlgorithmException e) {
e.printStackTrace();
}
return byteArrayToHexString(md.digest(data));
}