当前位置: 首页>>代码示例>>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;未经允许,请勿转载。