本文整理汇总了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 + ".");
}
示例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 + ".");
}
示例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 + ".");
}