本文整理汇总了Java中java.security.NoSuchAlgorithmException.toString方法的典型用法代码示例。如果您正苦于以下问题:Java NoSuchAlgorithmException.toString方法的具体用法?Java NoSuchAlgorithmException.toString怎么用?Java NoSuchAlgorithmException.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.security.NoSuchAlgorithmException
的用法示例。
在下文中一共展示了NoSuchAlgorithmException.toString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: digestBytes
import java.security.NoSuchAlgorithmException; //导入方法依赖的package包/类
/**
* Retrieves a byte sequence representing the MD5 digest of the
* specified byte sequence.
*
* @param data the data to digest.
* @return the MD5 digest as an array of 16 bytes.
* @throws HsqlUnsupportedOperationException if an MD5 digest
* algorithm is not available through the
* java.security.MessageDigest spi
*/
public static final byte[] digestBytes(byte[] data)
throws RuntimeException {
synchronized (MD5.class) {
if (md5 == null) {
try {
md5 = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e.toString());
}
}
return md5.digest(data);
}
}
示例2: digest
import java.security.NoSuchAlgorithmException; //导入方法依赖的package包/类
/**
* Generate a base-64 encoded digest of the idPasswordPair pair
* @param idPasswordPair id:password
* @return a string that can be used for authentication
*/
public String digest(String idPasswordPair) throws IOException {
if (StringUtils.isEmpty(idPasswordPair) || !isValid(idPasswordPair)) {
throw new IOException("Invalid id:password: " + idPasswordPair);
}
try {
return DigestAuthenticationProvider.generateDigest(idPasswordPair);
} catch (NoSuchAlgorithmException e) {
// unlikely since it is standard to the JVM, but maybe JCE restrictions
// could trigger it
throw new IOException(e.toString(), e);
}
}
示例3: getRawKey
import java.security.NoSuchAlgorithmException; //导入方法依赖的package包/类
private static byte[] getRawKey(String seedString) {
try {
byte[] seed = ("fe-"+seedString+"-ri").getBytes(StandardCharsets.UTF_8);
// Create MD5 Hash
MessageDigest digest;
digest = java.security.MessageDigest.getInstance("MD5");
digest.update(seed);
byte messageDigest[] = digest.digest();
byte[] result = new byte[16];
System.arraycopy(messageDigest, 0, result, 0, 16);
return result;
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e.toString(), e);
}
}
示例4: decryptChiData
import java.security.NoSuchAlgorithmException; //导入方法依赖的package包/类
static byte[] decryptChiData(byte[] data, byte[] passDigest) throws MyUtilException
{
int length = data.length;
int size = getChiSize(data);
if(size < 0)
throw new MyUtilException(R.string.error_invalid_chi, "not a valid chi file");
if(passDigest == null)
throw new MyUtilException(R.string.error_null_passdigest, "password input error");
int ret = bfdecrypt(data, 8, length - 8, passDigest);
if(ret < 0)
throw new MyUtilException(R.string.error_blowfish, "error decrypting/encrypting");
byte[] includedMD5 = new byte[16];
System.arraycopy(data, 16, includedMD5, 0, 16);
byte[] computedMD5;
try
{
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.update(data, 32, size);
computedMD5 = md5.digest();
}
catch(NoSuchAlgorithmException e)
{
throw new MyUtilException(R.string.error_unsupported, e.toString());
}
if(!MessageDigest.isEqual(includedMD5, computedMD5))
{
throw new MyUtilException(R.string.error_password, "Password is not correct.");
}
byte[] dec_data = new byte[size];
System.arraycopy(data, 32, dec_data, 0, size);
return dec_data;
}
示例5: decryptChsData
import java.security.NoSuchAlgorithmException; //导入方法依赖的package包/类
static byte[] decryptChsData(byte[] data, byte[] passDigest) throws MyUtilException
{
int length = data.length;
int size = getChiSize(data);
if(size < 0)
throw new MyUtilException(R.string.error_invalid_chi, "not a valid chi file");
if(passDigest == null)
throw new MyUtilException(R.string.error_null_passdigest, "password input error");
int ret = bfdecrypt(data, 8, 8, passDigest);
if(ret < 0)
throw new MyUtilException(R.string.error_blowfish, "error decrypting/encrypting");
byte[] iv = new byte[8];
System.arraycopy(data, 8, iv, 0, 8);
ret = bfdecrypt(data, 16, length - 16, passDigest, iv);
if(ret < 0)
throw new MyUtilException(R.string.error_blowfish, "error decrypting/encrypting");
byte[] includedMD5 = new byte[16];
System.arraycopy(data, 16, includedMD5, 0, 16);
byte[] computedMD5;
try
{
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.update(data, 32, size);
computedMD5 = md5.digest();
}
catch(NoSuchAlgorithmException e)
{
throw new MyUtilException(R.string.error_unsupported, e.toString());
}
if(!MessageDigest.isEqual(includedMD5, computedMD5))
{
throw new MyUtilException(R.string.error_password, "Password is not correct.");
}
byte[] dec_data = new byte[size];
System.arraycopy(data, 32, dec_data, 0, size);
return dec_data;
}