{
pki = PrivateKeyInfo.getInstance(ASN1Primitive.fromByteArray(encKey));
}
catch (IOException e)
{
throw new InvalidKeySpecException("Unable to decode PKCS8EncodedKeySpec: " + e);
}
try
{
ASN1Primitive innerType = pki.parsePrivateKey().toASN1Primitive();
// build and return the actual key
ASN1Sequence privKey = (ASN1Sequence)innerType;
// decode oidString (but we don't need it right now)
String oidString = ((ASN1ObjectIdentifier)privKey.getObjectAt(0))
.toString();
// decode <n>
BigInteger bigN = ((ASN1Integer)privKey.getObjectAt(1)).getValue();
int n = bigN.intValue();
// decode <k>
BigInteger bigK = ((ASN1Integer)privKey.getObjectAt(2)).getValue();
int k = bigK.intValue();
// decode <fieldPoly>
byte[] encFieldPoly = ((ASN1OctetString)privKey.getObjectAt(3))
.getOctets();
// decode <goppaPoly>
byte[] encGoppaPoly = ((ASN1OctetString)privKey.getObjectAt(4))
.getOctets();
// decode <sInv>
byte[] encSInv = ((ASN1OctetString)privKey.getObjectAt(5)).getOctets();
// decode <p1>
byte[] encP1 = ((ASN1OctetString)privKey.getObjectAt(6)).getOctets();
// decode <p2>
byte[] encP2 = ((ASN1OctetString)privKey.getObjectAt(7)).getOctets();
//decode <h>
byte[] encH = ((ASN1OctetString)privKey.getObjectAt(8)).getOctets();
// decode <qInv>
ASN1Sequence qSeq = (ASN1Sequence)privKey.getObjectAt(9);
byte[][] encQInv = new byte[qSeq.size()][];
for (int i = 0; i < qSeq.size(); i++)
{
encQInv[i] = ((ASN1OctetString)qSeq.getObjectAt(i)).getOctets();
}
return new BCMcEliecePrivateKey(new McEliecePrivateKeySpec(OID, n, k,
encFieldPoly, encGoppaPoly, encSInv, encP1, encP2,
encH, encQInv));
}
catch (IOException cce)
{
throw new InvalidKeySpecException(
"Unable to decode PKCS8EncodedKeySpec.");
}
}
throw new InvalidKeySpecException("Unsupported key specification: "
+ keySpec.getClass() + ".");
}