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


Java KeySpec.getClass方法代码示例

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


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

示例1: engineGeneratePrivate

import java.security.spec.KeySpec; //导入方法依赖的package包/类
/**
 * Converts, if possible, a key specification into a
 * {@link BCRainbowPrivateKey}. Currently, the following key specifications
 * are supported: {@link RainbowPrivateKeySpec}, {@link PKCS8EncodedKeySpec}.
 * <p/>
 * <p/>
 * <p/>
 * The ASN.1 definition of the key structure is
 * <p/>
 * <pre>
 *   RainbowPrivateKey ::= SEQUENCE {
 *     oid        OBJECT IDENTIFIER         -- OID identifying the algorithm
 *     A1inv      SEQUENCE OF OCTET STRING  -- inversed matrix of L1
 *     b1         OCTET STRING              -- translation vector of L1
 *     A2inv      SEQUENCE OF OCTET STRING  -- inversed matrix of L2
 *     b2         OCTET STRING              -- translation vector of L2
 *     vi         OCTET STRING              -- num of elmts in each Set S
 *     layers     SEQUENCE OF Layer         -- layers of F
 *   }
 *
 *   Layer             ::= SEQUENCE OF Poly
 *   Poly              ::= SEQUENCE {
 *     alpha      SEQUENCE OF OCTET STRING
 *     beta       SEQUENCE OF OCTET STRING
 *     gamma      OCTET STRING
 *     eta        OCTET
 *   }
 * </pre>
 * <p/>
 * <p/>
 *
 * @param keySpec the key specification
 * @return the Rainbow private key
 * @throws InvalidKeySpecException if the KeySpec is not supported.
 */
public PrivateKey engineGeneratePrivate(KeySpec keySpec)
    throws InvalidKeySpecException
{
    if (keySpec instanceof RainbowPrivateKeySpec)
    {
        return new BCRainbowPrivateKey((RainbowPrivateKeySpec)keySpec);
    }
    else if (keySpec instanceof PKCS8EncodedKeySpec)
    {
        // get the DER-encoded Key according to PKCS#8 from the spec
        byte[] encKey = ((PKCS8EncodedKeySpec)keySpec).getEncoded();

        try
        {
            return generatePrivate(PrivateKeyInfo.getInstance(ASN1Primitive.fromByteArray(encKey)));
        }
        catch (Exception e)
        {
            throw new InvalidKeySpecException(e.toString());
        }
    }

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

示例2: generatePublic

import java.security.spec.KeySpec; //导入方法依赖的package包/类
/**
 * Converts, if possible, a key specification into a
 * {@link BCMcElieceCCA2PublicKey}. Currently, the following key
 * specifications are supported: {@link McElieceCCA2PublicKeySpec},
 * {@link X509EncodedKeySpec}.
 *
 * @param keySpec the key specification
 * @return the McEliece CCA2 public key
 * @throws InvalidKeySpecException if the key specification is not supported.
 */
public PublicKey generatePublic(KeySpec keySpec)
    throws InvalidKeySpecException
{
    if (keySpec instanceof McElieceCCA2PublicKeySpec)
    {
        return new BCMcElieceCCA2PublicKey(
            (McElieceCCA2PublicKeySpec)keySpec);
    }
    else if (keySpec instanceof X509EncodedKeySpec)
    {
        // get the DER-encoded Key according to X.509 from the spec
        byte[] encKey = ((X509EncodedKeySpec)keySpec).getEncoded();

        // decode the SubjectPublicKeyInfo data structure to the pki object
        SubjectPublicKeyInfo pki;
        try
        {
            pki = SubjectPublicKeyInfo.getInstance(ASN1Primitive.fromByteArray(encKey));
        }
        catch (IOException e)
        {
            throw new InvalidKeySpecException(e.toString());
        }


        try
        {
            // --- Build and return the actual key.
            ASN1Primitive innerType = pki.parsePublicKey();
            ASN1Sequence publicKey = (ASN1Sequence)innerType;

            // decode oidString (but we don't need it right now)
            String oidString = ((ASN1ObjectIdentifier)publicKey.getObjectAt(0))
                .toString();

            // decode <n>
            BigInteger bigN = ((ASN1Integer)publicKey.getObjectAt(1)).getValue();
            int n = bigN.intValue();

            // decode <t>
            BigInteger bigT = ((ASN1Integer)publicKey.getObjectAt(2)).getValue();
            int t = bigT.intValue();

            // decode <matrixG>
            byte[] matrixG = ((ASN1OctetString)publicKey.getObjectAt(3)).getOctets();

            return new BCMcElieceCCA2PublicKey(new McElieceCCA2PublicKeySpec(
                OID, n, t, matrixG));
        }
        catch (IOException cce)
        {
            throw new InvalidKeySpecException(
                "Unable to decode X509EncodedKeySpec: "
                    + cce.getMessage());
        }
    }

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

示例3: generatePublic

import java.security.spec.KeySpec; //导入方法依赖的package包/类
/**
 * Converts, if possible, a key specification into a
 * {@link BCMcEliecePublicKey}. Currently, the following key specifications
 * are supported: {@link McEliecePublicKeySpec}, {@link X509EncodedKeySpec}.
 *
 * @param keySpec the key specification
 * @return the McEliece public key
 * @throws InvalidKeySpecException if the key specification is not supported.
 */
public PublicKey generatePublic(KeySpec keySpec)
    throws InvalidKeySpecException
{
    if (keySpec instanceof McEliecePublicKeySpec)
    {
        return new BCMcEliecePublicKey((McEliecePublicKeySpec)keySpec);
    }
    else if (keySpec instanceof X509EncodedKeySpec)
    {
        // get the DER-encoded Key according to X.509 from the spec
        byte[] encKey = ((X509EncodedKeySpec)keySpec).getEncoded();

        // decode the SubjectPublicKeyInfo data structure to the pki object
        SubjectPublicKeyInfo pki;
        try
        {
            pki = SubjectPublicKeyInfo.getInstance(ASN1Primitive.fromByteArray(encKey));
        }
        catch (IOException e)
        {
            throw new InvalidKeySpecException(e.toString());
        }

        try
        {
            // --- Build and return the actual key.
            ASN1Primitive innerType = pki.parsePublicKey();
            ASN1Sequence publicKey = (ASN1Sequence)innerType;

            // decode oidString (but we don't need it right now)
            String oidString = ((ASN1ObjectIdentifier)publicKey.getObjectAt(0))
                .toString();

            // decode <n>
            BigInteger bigN = ((ASN1Integer)publicKey.getObjectAt(1)).getValue();
            int n = bigN.intValue();

            // decode <t>
            BigInteger bigT = ((ASN1Integer)publicKey.getObjectAt(2)).getValue();
            int t = bigT.intValue();

            // decode <matrixG>
            byte[] matrixG = ((ASN1OctetString)publicKey.getObjectAt(3)).getOctets();


            return new BCMcEliecePublicKey(new McEliecePublicKeySpec(OID, t, n,
                matrixG));
        }
        catch (IOException cce)
        {
            throw new InvalidKeySpecException(
                "Unable to decode X509EncodedKeySpec: "
                    + cce.getMessage());
        }
    }

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


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