use of org.mozilla.jss.pkix.primitive.SubjectPublicKeyInfo in project jss by dogtagpki.
the class JSSCipherSpi method engineGetKeySize.
@Override
public int engineGetKeySize(Key key) throws InvalidKeyException {
if (key instanceof PK11PrivKey) {
return ((PK11PrivKey) key).getStrength();
} else if (key instanceof PK11PubKey) {
try {
byte[] encoded = ((PK11PubKey) key).getEncoded();
SubjectPublicKeyInfo.Template spkiTemp = new SubjectPublicKeyInfo.Template();
SubjectPublicKeyInfo spki = (SubjectPublicKeyInfo) ASN1Util.decode(spkiTemp, encoded);
BIT_STRING pk = spki.getSubjectPublicKey();
return pk.getBits().length - pk.getPadCount();
} catch (InvalidBERException e) {
throw new InvalidKeyException("Exception while decoding " + "public key: " + e.getMessage());
}
} else if (key instanceof SecretKeyFacade) {
SymmetricKey symkey = ((SecretKeyFacade) key).key;
return symkey.getLength();
} else {
key = importKey(key);
SymmetricKey symkey = ((SecretKeyFacade) key).key;
return symkey.getLength();
}
}
Aggregations