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