本文整理汇总了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));
}