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


Java InvalidKeySpecException.getMessage方法代碼示例

本文整理匯總了Java中java.security.spec.InvalidKeySpecException.getMessage方法的典型用法代碼示例。如果您正苦於以下問題:Java InvalidKeySpecException.getMessage方法的具體用法?Java InvalidKeySpecException.getMessage怎麽用?Java InvalidKeySpecException.getMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.security.spec.InvalidKeySpecException的用法示例。


在下文中一共展示了InvalidKeySpecException.getMessage方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: engineGetKey

import java.security.spec.InvalidKeySpecException; //導入方法依賴的package包/類
public Key engineGetKey(String alias, char[] password)
    throws NoSuchAlgorithmException, UnrecoverableKeyException
{
    alias = alias.toLowerCase();

    if (!privateKeys.containsKey(alias))
        return null;
    byte[] key = decryptKey((byte[]) privateKeys.get(alias),
        charsToBytes(password));
    Certificate[] chain = engineGetCertificateChain(alias);
    if (chain.length > 0)
    {
        try
        {
            // Private and public keys MUST have the same algorithm.
            KeyFactory fact = KeyFactory.getInstance(
                chain[0].getPublicKey().getAlgorithm());
            return fact.generatePrivate(new PKCS8EncodedKeySpec(key));
        }
        catch (InvalidKeySpecException x)
        {
            throw new UnrecoverableKeyException(x.getMessage());
        }
    }
    else
        return new SecretKeySpec(key, alias);
}
 
開發者ID:uhuru-mobile,項目名稱:mobile-store,代碼行數:28,代碼來源:JKS.java

示例2: engineTranslateKey

import java.security.spec.InvalidKeySpecException; //導入方法依賴的package包/類
/**
 * Translates a key object, whose provider may be unknown or potentially
 * untrusted, into a corresponding key object of this key factory.
 *
 * @param key the key whose provider is unknown or untrusted
 *
 * @return the translated key
 *
 * @exception InvalidKeyException if the given key cannot be processed by
 * this key factory.
 */
protected Key engineTranslateKey(Key key) throws InvalidKeyException {

    try {

        if (key instanceof java.security.interfaces.DSAPublicKey) {
            // Check if key originates from this factory
            if (key instanceof sun.security.provider.DSAPublicKey) {
                return key;
            }
            // Convert key to spec
            DSAPublicKeySpec dsaPubKeySpec
                = engineGetKeySpec(key, DSAPublicKeySpec.class);
            // Create key from spec, and return it
            return engineGeneratePublic(dsaPubKeySpec);

        } else if (key instanceof java.security.interfaces.DSAPrivateKey) {
            // Check if key originates from this factory
            if (key instanceof sun.security.provider.DSAPrivateKey) {
                return key;
            }
            // Convert key to spec
            DSAPrivateKeySpec dsaPrivKeySpec
                = engineGetKeySpec(key, DSAPrivateKeySpec.class);
            // Create key from spec, and return it
            return engineGeneratePrivate(dsaPrivKeySpec);

        } else {
            throw new InvalidKeyException("Wrong algorithm type");
        }

    } catch (InvalidKeySpecException e) {
        throw new InvalidKeyException("Cannot translate key: "
                                      + e.getMessage());
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:47,代碼來源:DSAKeyFactory.java

示例3: engineTranslateKey

import java.security.spec.InvalidKeySpecException; //導入方法依賴的package包/類
/**
 * Translates a <code>SecretKey</code> object, whose provider may be
 * unknown or potentially untrusted, into a corresponding
 * <code>SecretKey</code> object of this key factory.
 *
 * @param key the key whose provider is unknown or untrusted
 *
 * @return the translated key
 *
 * @exception InvalidKeyException if the given key cannot be processed by
 * this key factory.
 */
protected SecretKey engineTranslateKey(SecretKey key)
    throws InvalidKeyException
{
    try {
        if ((key != null) &&
            (validTypes.contains(key.getAlgorithm().toUpperCase())) &&
            (key.getFormat().equalsIgnoreCase("RAW"))) {

            // Check if key originates from this factory
            if (key instanceof com.sun.crypto.provider.PBEKey) {
                return key;
            }

            // Convert key to spec
            PBEKeySpec pbeKeySpec = (PBEKeySpec)engineGetKeySpec
                (key, PBEKeySpec.class);

            // Create key from spec, and return it
            return engineGenerateSecret(pbeKeySpec);
        } else {
            throw new InvalidKeyException("Invalid key format/algorithm");
        }

    } catch (InvalidKeySpecException ikse) {
        throw new InvalidKeyException("Cannot translate key: "
                                      + ikse.getMessage());
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:41,代碼來源:PBEKeyFactory.java

示例4: engineTranslateKey

import java.security.spec.InvalidKeySpecException; //導入方法依賴的package包/類
/**
 * Translates a <code>SecretKey</code> object, whose provider may be
 * unknown or potentially untrusted, into a corresponding
 * <code>SecretKey</code> object of this key factory.
 *
 * @param key the key whose provider is unknown or untrusted
 *
 * @return the translated key
 *
 * @exception InvalidKeyException if the given key cannot be processed by
 * this key factory.
 */
protected SecretKey engineTranslateKey(SecretKey key)
    throws InvalidKeyException
{
    try {
        if ((key != null) &&
            (validTypes.contains(key.getAlgorithm().toUpperCase(Locale.ENGLISH))) &&
            (key.getFormat().equalsIgnoreCase("RAW"))) {

            // Check if key originates from this factory
            if (key instanceof com.sun.crypto.provider.PBEKey) {
                return key;
            }

            // Convert key to spec
            PBEKeySpec pbeKeySpec = (PBEKeySpec)engineGetKeySpec
                (key, PBEKeySpec.class);

            // Create key from spec, and return it
            return engineGenerateSecret(pbeKeySpec);
        } else {
            throw new InvalidKeyException("Invalid key format/algorithm");
        }

    } catch (InvalidKeySpecException ikse) {
        throw new InvalidKeyException("Cannot translate key: "
                                      + ikse.getMessage());
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:41,代碼來源:PBEKeyFactory.java


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