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


Java NoSuchAlgorithmException.printStackTrace方法代码示例

本文整理汇总了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 "";
}
 
开发者ID:akarshsingh9,项目名称:CodeInPython,代码行数:19,代码来源:quiz10Fragment.java

示例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;
}
 
开发者ID:tojaoomy,项目名称:private-WeChat,代码行数:34,代码来源:SignUtil.java

示例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();
}
 
开发者ID:jopenbox,项目名称:android-lite-utils,代码行数:27,代码来源:SHA512Utils.java

示例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;
}
 
开发者ID:yanghanxy,项目名称:CloudDB,代码行数:21,代码来源:ConsistentHashing.java

示例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();
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:14,代码来源:Device.java

示例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;
}
 
开发者ID:feup-infolab,项目名称:labtablet,代码行数:16,代码来源:Utils.java

示例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;
}
 
开发者ID:wjggwm,项目名称:webside,代码行数:17,代码来源:MD5.java

示例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;
    }
}
 
开发者ID:pan2yong22,项目名称:AndroidUtilCode-master,代码行数:19,代码来源:EncryptUtils.java

示例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;  
       }  
   }
 
开发者ID:landriesnidis,项目名称:PCloud_Server_v3,代码行数:18,代码来源:MD5.java

示例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 "";
}
 
开发者ID:karlos7,项目名称:ViolenciaContraMulher,代码行数:11,代码来源:Criptografia.java

示例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;
}
 
开发者ID:LanguidSheep,项目名称:sealtalk-android-master,代码行数:21,代码来源:MD5.java

示例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;
    }
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:10,代码来源:MD5Utils.java

示例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;
}
 
开发者ID:mDL-ILP,项目名称:mDL-ILP,代码行数:15,代码来源:CardIOUtils.java

示例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());
}
 
开发者ID:wkmeijer,项目名称:CS4160-trustchain-android,代码行数:17,代码来源:TrustChainBlock.java

示例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));
}
 
开发者ID:messagemedia,项目名称:messages-java-sdk,代码行数:18,代码来源:TestHelper.java


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