当前位置: 首页>>代码示例>>Java>>正文


Java Key.getClass方法代码示例

本文整理汇总了Java中java.security.Key.getClass方法的典型用法代码示例。如果您正苦于以下问题:Java Key.getClass方法的具体用法?Java Key.getClass怎么用?Java Key.getClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.security.Key的用法示例。


在下文中一共展示了Key.getClass方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: engineGetKeySpec

import java.security.Key; //导入方法依赖的package包/类
/**
 * Converts a given key into a key specification, if possible. Currently the
 * following specs are supported:
 * <ul>
 * <li>for RainbowPublicKey: X509EncodedKeySpec, RainbowPublicKeySpec
 * <li>for RainbowPrivateKey: PKCS8EncodedKeySpec, RainbowPrivateKeySpec
 * </ul>
 *
 * @param key     the key
 * @param keySpec the key specification
 * @return the specification of the CMSS key
 * @throws InvalidKeySpecException if the key type or key specification is not supported.
 */
public final KeySpec engineGetKeySpec(Key key, Class keySpec)
    throws InvalidKeySpecException
{
    if (key instanceof BCRainbowPrivateKey)
    {
        if (PKCS8EncodedKeySpec.class.isAssignableFrom(keySpec))
        {
            return new PKCS8EncodedKeySpec(key.getEncoded());
        }
        else if (RainbowPrivateKeySpec.class.isAssignableFrom(keySpec))
        {
            BCRainbowPrivateKey privKey = (BCRainbowPrivateKey)key;
            return new RainbowPrivateKeySpec(privKey.getInvA1(), privKey
                .getB1(), privKey.getInvA2(), privKey.getB2(), privKey
                .getVi(), privKey.getLayers());
        }
    }
    else if (key instanceof BCRainbowPublicKey)
    {
        if (X509EncodedKeySpec.class.isAssignableFrom(keySpec))
        {
            return new X509EncodedKeySpec(key.getEncoded());
        }
        else if (RainbowPublicKeySpec.class.isAssignableFrom(keySpec))
        {
            BCRainbowPublicKey pubKey = (BCRainbowPublicKey)key;
            return new RainbowPublicKeySpec(pubKey.getDocLength(), pubKey
                .getCoeffQuadratic(), pubKey.getCoeffSingular(), pubKey
                .getCoeffScalar());
        }
    }
    else
    {
        throw new InvalidKeySpecException("Unsupported key type: "
            + key.getClass() + ".");
    }

    throw new InvalidKeySpecException("Unknown key specification: "
        + keySpec + ".");
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:54,代码来源:RainbowKeyFactorySpi.java

示例2: getKeySpec

import java.security.Key; //导入方法依赖的package包/类
/**
 * Converts, if possible, a given key into a key specification. Currently,
 * the following key specifications are supported:
 * <ul>
 * <li>for McElieceCCA2PublicKey: {@link X509EncodedKeySpec},
 * {@link McElieceCCA2PublicKeySpec}</li>
 * <li>for McElieceCCA2PrivateKey: {@link PKCS8EncodedKeySpec},
 * {@link McElieceCCA2PrivateKeySpec}</li>.
 * </ul>
 *
 * @param key     the key
 * @param keySpec the key specification
 * @return the specification of the McEliece CCA2 key
 * @throws InvalidKeySpecException if the key type or the key specification is not
 * supported.
 * @see BCMcElieceCCA2PrivateKey
 * @see McElieceCCA2PrivateKeySpec
 * @see BCMcElieceCCA2PublicKey
 * @see McElieceCCA2PublicKeySpec
 */
public KeySpec getKeySpec(Key key, Class keySpec)
    throws InvalidKeySpecException
{
    if (key instanceof BCMcElieceCCA2PrivateKey)
    {
        if (PKCS8EncodedKeySpec.class.isAssignableFrom(keySpec))
        {
            return new PKCS8EncodedKeySpec(key.getEncoded());
        }
        else if (McElieceCCA2PrivateKeySpec.class
            .isAssignableFrom(keySpec))
        {
            BCMcElieceCCA2PrivateKey privKey = (BCMcElieceCCA2PrivateKey)key;
            return new McElieceCCA2PrivateKeySpec(OID, privKey.getN(), privKey
                .getK(), privKey.getField(), privKey.getGoppaPoly(),
                privKey.getP(), privKey.getH(), privKey.getQInv());
        }
    }
    else if (key instanceof BCMcElieceCCA2PublicKey)
    {
        if (X509EncodedKeySpec.class.isAssignableFrom(keySpec))
        {
            return new X509EncodedKeySpec(key.getEncoded());
        }
        else if (McElieceCCA2PublicKeySpec.class
            .isAssignableFrom(keySpec))
        {
            BCMcElieceCCA2PublicKey pubKey = (BCMcElieceCCA2PublicKey)key;
            return new McElieceCCA2PublicKeySpec(OID, pubKey.getN(), pubKey
                .getT(), pubKey.getG());
        }
    }
    else
    {
        throw new InvalidKeySpecException("Unsupported key type: "
            + key.getClass() + ".");
    }

    throw new InvalidKeySpecException("Unknown key specification: "
        + keySpec + ".");
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:62,代码来源:McElieceCCA2KeyFactorySpi.java

示例3: getKeySpec

import java.security.Key; //导入方法依赖的package包/类
/**
 * Converts, if possible, a given key into a key specification. Currently,
 * the following key specifications are supported:
 * <ul>
 * <li>for McEliecePublicKey: {@link X509EncodedKeySpec},
 * {@link McEliecePublicKeySpec}</li>
 * <li>for McEliecePrivateKey: {@link PKCS8EncodedKeySpec},
 * {@link McEliecePrivateKeySpec}</li>.
 * </ul>
 *
 * @param key     the key
 * @param keySpec the key specification
 * @return the specification of the McEliece key
 * @throws InvalidKeySpecException if the key type or the key specification is not
 * supported.
 * @see BCMcEliecePrivateKey
 * @see McEliecePrivateKeySpec
 * @see BCMcEliecePublicKey
 * @see McEliecePublicKeySpec
 */
public KeySpec getKeySpec(Key key, Class keySpec)
    throws InvalidKeySpecException
{
    if (key instanceof BCMcEliecePrivateKey)
    {
        if (PKCS8EncodedKeySpec.class.isAssignableFrom(keySpec))
        {
            return new PKCS8EncodedKeySpec(key.getEncoded());
        }
        else if (McEliecePrivateKeySpec.class.isAssignableFrom(keySpec))
        {
            BCMcEliecePrivateKey privKey = (BCMcEliecePrivateKey)key;
            return new McEliecePrivateKeySpec(OID, privKey.getN(), privKey
                .getK(), privKey.getField(), privKey.getGoppaPoly(),
                privKey.getSInv(), privKey.getP1(), privKey.getP2(),
                privKey.getH(), privKey.getQInv());
        }
    }
    else if (key instanceof BCMcEliecePublicKey)
    {
        if (X509EncodedKeySpec.class.isAssignableFrom(keySpec))
        {
            return new X509EncodedKeySpec(key.getEncoded());
        }
        else if (McEliecePublicKeySpec.class.isAssignableFrom(keySpec))
        {
            BCMcEliecePublicKey pubKey = (BCMcEliecePublicKey)key;
            return new McEliecePublicKeySpec(OID, pubKey.getN(), pubKey.getT(),
                pubKey.getG());
        }
    }
    else
    {
        throw new InvalidKeySpecException("Unsupported key type: "
            + key.getClass() + ".");
    }

    throw new InvalidKeySpecException("Unknown key specification: "
        + keySpec + ".");
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:61,代码来源:McElieceKeyFactorySpi.java


注:本文中的java.security.Key.getClass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。