本文整理汇总了Java中java.security.NoSuchAlgorithmException.getMessage方法的典型用法代码示例。如果您正苦于以下问题:Java NoSuchAlgorithmException.getMessage方法的具体用法?Java NoSuchAlgorithmException.getMessage怎么用?Java NoSuchAlgorithmException.getMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.security.NoSuchAlgorithmException
的用法示例。
在下文中一共展示了NoSuchAlgorithmException.getMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateBubiAddress
import java.security.NoSuchAlgorithmException; //导入方法依赖的package包/类
/**
* 根据公钥生成布比地址 1.对Q进行RIPEMD160算法得到20字节的N,即N = RIPEMD160(Q)
* 2.在N前面加4字节前缀和1字节版本号。即M=0XE69A73FF01+N
* 3.对M进行两次SHA256算法取前四字节,即Checksum=SHA256(SHA256(M))的前4字节
* 4.将Checksum加到M后面,即S=M+Checksum 5.对S进行Base58编码即得到布比地址bubixxxxxxxxxxxx
*
* @param pubKey
* @return 布比地址字符串
*/
private static String generateBubiAddress(EdDSAPublicKey pubKey){
try {
MessageDigest md = MessageDigest.getInstance("RIPEMD160");
md.update(pubKey.getAbyte());
byte[] N = md.digest();
byte[] pubKeyheadArr = Utils.hexToBytes("E69A73FF01");
byte[] M = ArrayUtils.addAll(pubKeyheadArr, N);
md = MessageDigest.getInstance("SHA-256");
md.update(M);
byte[] M_256_1 = md.digest();
md.update(M_256_1);
byte[] M_256_2 = md.digest();
byte[] S = new byte[M.length + 4];
System.arraycopy(M, 0, S, 0, M.length);
System.arraycopy(M_256_2, 0, S, M.length, 4);
return Base58Utils.encode(S);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("Error occured on generating BubiAddress!--" + e.getMessage(), e);
}
}
示例2: unmarshalKeyValue
import java.security.NoSuchAlgorithmException; //导入方法依赖的package包/类
PublicKey unmarshalKeyValue(Element kvtElem)
throws MarshalException
{
if (rsakf == null) {
try {
rsakf = KeyFactory.getInstance("RSA");
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException
("unable to create RSA KeyFactory: " + e.getMessage());
}
}
Element modulusElem = DOMUtils.getFirstChildElement(kvtElem,
"Modulus");
modulus = new DOMCryptoBinary(modulusElem.getFirstChild());
Element exponentElem = DOMUtils.getNextSiblingElement(modulusElem,
"Exponent");
exponent = new DOMCryptoBinary(exponentElem.getFirstChild());
RSAPublicKeySpec spec = new RSAPublicKeySpec(modulus.getBigNum(),
exponent.getBigNum());
return generatePublicKey(rsakf, spec);
}
示例3: generateToken
import java.security.NoSuchAlgorithmException; //导入方法依赖的package包/类
public String generateToken(String email, String password, Jedis resource) {
byte[] tokenGeneratedByte = (email + password + System.currentTimeMillis() / 2).getBytes();
String tokenGenerated = "";
try {
tokenGenerated = MessageDigest.getInstance("MD5").digest(tokenGeneratedByte).toString();
new UserGateway(resource).updateTokenSession(email, password, tokenGenerated);
return tokenGenerated;
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e.getMessage());
}
}
示例4: encodeMd5
import java.security.NoSuchAlgorithmException; //导入方法依赖的package包/类
public static String encodeMd5(byte[] source) {
try {
return encodeHex(MessageDigest.getInstance("MD5").digest(source));
} catch (NoSuchAlgorithmException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
示例5: computeSignature
import java.security.NoSuchAlgorithmException; //导入方法依赖的package包/类
/**
* Returns then signature of a string.
*
* @param secret The secret to use
* @param str string to sign.
*
* @return the signature for the string.
*/
protected String computeSignature(byte[] secret, String str) {
try {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(str.getBytes(Charset.forName("UTF-8")));
md.update(secret);
byte[] digest = md.digest();
return new Base64(0).encodeToString(digest);
} catch (NoSuchAlgorithmException ex) {
throw new RuntimeException("It should not happen, " + ex.getMessage(), ex);
}
}
示例6: getInstance
import java.security.NoSuchAlgorithmException; //导入方法依赖的package包/类
public static X509Store getInstance(String type, X509StoreParameters parameters)
throws NoSuchStoreException
{
try
{
X509Util.Implementation impl = X509Util.getImplementation("X509Store", type);
return createStore(impl, parameters);
}
catch (NoSuchAlgorithmException e)
{
throw new NoSuchStoreException(e.getMessage());
}
}
示例7: computeMethodHash
import java.security.NoSuchAlgorithmException; //导入方法依赖的package包/类
/**
* Compute the "method hash" of a remote method. The method hash
* is a long containing the first 64 bits of the SHA digest from
* the UTF encoded string of the method name and descriptor.
*/
public static long computeMethodHash(Method m) {
long hash = 0;
ByteArrayOutputStream sink = new ByteArrayOutputStream(127);
try {
MessageDigest md = MessageDigest.getInstance("SHA");
DataOutputStream out = new DataOutputStream(
new DigestOutputStream(sink, md));
String s = getMethodNameAndDescriptor(m);
if (serverRefLog.isLoggable(Log.VERBOSE)) {
serverRefLog.log(Log.VERBOSE,
"string used for method hash: \"" + s + "\"");
}
out.writeUTF(s);
// use only the first 64 bits of the digest for the hash
out.flush();
byte hasharray[] = md.digest();
for (int i = 0; i < Math.min(8, hasharray.length); i++) {
hash += ((long) (hasharray[i] & 0xFF)) << (i * 8);
}
} catch (IOException ignore) {
/* can't happen, but be deterministic anyway. */
hash = -1;
} catch (NoSuchAlgorithmException complain) {
throw new SecurityException(complain.getMessage());
}
return hash;
}
示例8: encodeMd5
import java.security.NoSuchAlgorithmException; //导入方法依赖的package包/类
public static String encodeMd5(byte[] source) {
try {
return encodeHex(MessageDigest.getInstance("MD5").digest(source));
} catch (NoSuchAlgorithmException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
示例9: TimeStampTokenGenerator
import java.security.NoSuchAlgorithmException; //导入方法依赖的package包/类
/**
* basic creation - only the default attributes will be included here.
* @deprecated use SignerInfoGenerator constructor that takes a digest calculator
*/
public TimeStampTokenGenerator(
final SignerInfoGenerator signerInfoGen,
ASN1ObjectIdentifier tsaPolicy)
throws IllegalArgumentException, TSPException
{
this(new DigestCalculator()
{
private ByteArrayOutputStream bOut = new ByteArrayOutputStream();
public AlgorithmIdentifier getAlgorithmIdentifier()
{
return new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1, DERNull.INSTANCE);
}
public OutputStream getOutputStream()
{
return bOut;
}
public byte[] getDigest()
{
try
{
return MessageDigest.getInstance("SHA-1").digest(bOut.toByteArray());
}
catch (NoSuchAlgorithmException e)
{
throw new IllegalStateException("cannot find sha-1: "+ e.getMessage());
}
}
}, signerInfoGen, tsaPolicy);
}
示例10: getMessageDigest
import java.security.NoSuchAlgorithmException; //导入方法依赖的package包/类
public static MessageDigest getMessageDigest(String algorithm) {
try {
return MessageDigest.getInstance(algorithm);
} catch (NoSuchAlgorithmException e) {
Logger.logMessage("Missing message digest algorithm: " + algorithm);
throw new RuntimeException(e.getMessage(), e);
}
}
示例11: hash_256
import java.security.NoSuchAlgorithmException; //导入方法依赖的package包/类
/**
* 对指定的字节数组进行 SHA256 哈希;
*
* @param data
* @return 返回长度为 32 的字节数组;
*/
public static byte[] hash_256(byte[] bytes){
MessageDigest md = null;
try {
md = MessageDigest.getInstance("SHA-256");
md.update(bytes);
return md.digest();
} catch (NoSuchAlgorithmException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
示例12: getSSLContext
import java.security.NoSuchAlgorithmException; //导入方法依赖的package包/类
/**
* Получить экземпляр протокол безопасного сокета
*
* @return экземпляр протокола безопасного сокета
* @throws SystemException
* системное исключение -
*/
public static SSLContext getSSLContext() throws SystemException {
try {
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(new KeyManager[0], new TrustManager[] { new AllowingAllTrustManager() },
new SecureRandom());
SSLContext.setDefault(sslContext);
return sslContext;
} catch (NoSuchAlgorithmException nsae) {
throw new SystemException(" Unable get instance TLS: " + nsae.getMessage() + nsae);
} catch (KeyManagementException kme) {
throw new SystemException(" Unable init SSL context: " + kme.getMessage() + kme);
}
}
示例13: createSigner
import java.security.NoSuchAlgorithmException; //导入方法依赖的package包/类
public ConcurrentContentSigner createSigner(AlgorithmIdentifier signatureAlgId,
int parallelism, SecureRandom random) throws XiSecurityException {
ParamUtil.requireNonNull("signatureAlgId", signatureAlgId);
ParamUtil.requireMin("parallelism", parallelism, 1);
List<XiContentSigner> signers = new ArrayList<>(parallelism);
boolean gmac = false;
ASN1ObjectIdentifier oid = signatureAlgId.getAlgorithm();
if (oid.equals(NISTObjectIdentifiers.id_aes128_GCM)
|| oid.equals(NISTObjectIdentifiers.id_aes192_GCM)
|| oid.equals(NISTObjectIdentifiers.id_aes256_GCM)) {
gmac = true;
}
for (int i = 0; i < parallelism; i++) {
XiContentSigner signer;
if (gmac) {
signer = new AESGmacContentSigner(oid, key);
} else {
signer = new HmacContentSigner(signatureAlgId, key);
}
signers.add(signer);
}
final boolean mac = true;
DfltConcurrentContentSigner concurrentSigner;
try {
concurrentSigner = new DfltConcurrentContentSigner(mac, signers, key);
} catch (NoSuchAlgorithmException ex) {
throw new XiSecurityException(ex.getMessage(), ex);
}
concurrentSigner.setSha1DigestOfMacKey(HashAlgoType.SHA1.hash(key.getEncoded()));
return concurrentSigner;
}
示例14: computeStructuralUID
import java.security.NoSuchAlgorithmException; //导入方法依赖的package包/类
public static long computeStructuralUID(boolean hasWriteObject, Class<?> cl) {
ByteArrayOutputStream devnull = new ByteArrayOutputStream(512);
long h = 0;
try {
if ((!java.io.Serializable.class.isAssignableFrom(cl)) ||
(cl.isInterface())){
return 0;
}
if (java.io.Externalizable.class.isAssignableFrom(cl)) {
return 1;
}
MessageDigest md = MessageDigest.getInstance("SHA");
DigestOutputStream mdo = new DigestOutputStream(devnull, md);
DataOutputStream data = new DataOutputStream(mdo);
//In the old case, for the caller class, the write Method wasn't considered
// for rep-id calculations correctly, but for parent classes it was taken
// into account. That is the reason there is the klude of getting the write
// Object method in there
// Get SUID of parent
Class<?> parent = cl.getSuperclass();
if ((parent != null) && (parent != java.lang.Object.class)) {
boolean hasWriteObjectFlag = false;
Class [] args = {java.io.ObjectOutputStream.class};
Method hasWriteObjectMethod = ObjectStreamClassUtil_1_3.getDeclaredMethod(parent, "writeObject", args,
Modifier.PRIVATE, Modifier.STATIC);
if (hasWriteObjectMethod != null)
hasWriteObjectFlag = true;
data.writeLong(ObjectStreamClassUtil_1_3.computeStructuralUID(hasWriteObjectFlag, parent));
}
if (hasWriteObject)
data.writeInt(2);
else
data.writeInt(1);
/* Sort the field names to get a deterministic order */
Field[] field = ObjectStreamClassUtil_1_3.getDeclaredFields(cl);
Arrays.sort(field, compareMemberByName);
for (int i = 0; i < field.length; i++) {
Field f = field[i];
/* Include in the hash all fields except those that are
* transient or static.
*/
int m = f.getModifiers();
if (Modifier.isTransient(m) || Modifier.isStatic(m))
continue;
data.writeUTF(f.getName());
data.writeUTF(getSignature(f.getType()));
}
/* Compute the hash value for this class.
* Use only the first 64 bits of the hash.
*/
data.flush();
byte hasharray[] = md.digest();
int minimum = Math.min(8, hasharray.length);
for (int i = minimum; i > 0; i--) {
h += (long)(hasharray[i] & 255) << (i * 8);
}
} catch (IOException ignore) {
/* can't happen, but be deterministic anyway. */
h = -1;
} catch (NoSuchAlgorithmException complain) {
throw new SecurityException(complain.getMessage());
}
return h;
}
示例15: computeChannelBinding
import java.security.NoSuchAlgorithmException; //导入方法依赖的package包/类
private byte[] computeChannelBinding(ChannelBinding channelBinding)
throws GSSException {
InetAddress initiatorAddress = channelBinding.getInitiatorAddress();
InetAddress acceptorAddress = channelBinding.getAcceptorAddress();
int size = 5*4;
int initiatorAddressType = getAddrType(initiatorAddress);
int acceptorAddressType = getAddrType(acceptorAddress);
byte[] initiatorAddressBytes = null;
if (initiatorAddress != null) {
initiatorAddressBytes = getAddrBytes(initiatorAddress);
size += initiatorAddressBytes.length;
}
byte[] acceptorAddressBytes = null;
if (acceptorAddress != null) {
acceptorAddressBytes = getAddrBytes(acceptorAddress);
size += acceptorAddressBytes.length;
}
byte[] appDataBytes = channelBinding.getApplicationData();
if (appDataBytes != null) {
size += appDataBytes.length;
}
byte[] data = new byte[size];
int pos = 0;
writeLittleEndian(initiatorAddressType, data, pos);
pos += 4;
if (initiatorAddressBytes != null) {
writeLittleEndian(initiatorAddressBytes.length, data, pos);
pos += 4;
System.arraycopy(initiatorAddressBytes, 0,
data, pos, initiatorAddressBytes.length);
pos += initiatorAddressBytes.length;
} else {
// Write length 0
pos += 4;
}
writeLittleEndian(acceptorAddressType, data, pos);
pos += 4;
if (acceptorAddressBytes != null) {
writeLittleEndian(acceptorAddressBytes.length, data, pos);
pos += 4;
System.arraycopy(acceptorAddressBytes, 0,
data, pos, acceptorAddressBytes.length);
pos += acceptorAddressBytes.length;
} else {
// Write length 0
pos += 4;
}
if (appDataBytes != null) {
writeLittleEndian(appDataBytes.length, data, pos);
pos += 4;
System.arraycopy(appDataBytes, 0, data, pos,
appDataBytes.length);
pos += appDataBytes.length;
} else {
// Write 0
pos += 4;
}
try {
MessageDigest md5 = MessageDigest.getInstance("MD5");
return md5.digest(data);
} catch (NoSuchAlgorithmException e) {
throw new GSSException(GSSException.FAILURE, -1,
"Could not get MD5 Message Digest - "
+ e.getMessage());
}
}