當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。