當前位置: 首頁>>代碼示例>>Java>>正文


Java NoSuchAlgorithmException.getMessage方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:bubicn,項目名稱:bubichain-sdk-java,代碼行數:31,代碼來源:BlockchainKeyPairFactory.java

示例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);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:22,代碼來源:DOMKeyValue.java

示例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());
    }
}
 
開發者ID:wakanda-cloud,項目名稱:wakanda-security,代碼行數:12,代碼來源:LoginService.java

示例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);
	}
}
 
開發者ID:yunhaibin,項目名稱:dubbox-hystrix,代碼行數:8,代碼來源:Coder.java

示例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);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:20,代碼來源:Signer.java

示例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());
    }
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:15,代碼來源:X509Store.java

示例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;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:35,代碼來源:Util.java

示例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);
    }
}
 
開發者ID:l1325169021,項目名稱:github-test,代碼行數:8,代碼來源:Coder.java

示例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);
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:37,代碼來源:TimeStampTokenGenerator.java

示例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);
    }
}
 
開發者ID:muhatzg,項目名稱:burstcoin,代碼行數:9,代碼來源:Crypto.java

示例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);
    }
}
 
開發者ID:bubicn,項目名稱:bubichain-sdk-java,代碼行數:17,代碼來源:ShaUtils.java

示例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);
	}
}
 
開發者ID:onixred,項目名稱:golos4j,代碼行數:21,代碼來源:Util.java

示例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;
}
 
開發者ID:xipki,項目名稱:xitk,代碼行數:37,代碼來源:SoftTokenMacContentSignerBuilder.java

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:77,代碼來源:ObjectStreamClassUtil_1_3.java

示例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());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:80,代碼來源:InitialToken.java


注:本文中的java.security.NoSuchAlgorithmException.getMessage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。