Search in sources :

Example 6 with SubjectPublicKeyInfo

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();
    }
}
Also used : PK11PubKey(org.mozilla.jss.pkcs11.PK11PubKey) InvalidBERException(org.mozilla.jss.asn1.InvalidBERException) SecretKeyFacade(org.mozilla.jss.crypto.SecretKeyFacade) SymmetricKey(org.mozilla.jss.crypto.SymmetricKey) InvalidKeyException(java.security.InvalidKeyException) PK11PrivKey(org.mozilla.jss.pkcs11.PK11PrivKey) SubjectPublicKeyInfo(org.mozilla.jss.pkix.primitive.SubjectPublicKeyInfo) BIT_STRING(org.mozilla.jss.asn1.BIT_STRING)

Aggregations

SubjectPublicKeyInfo (org.mozilla.jss.pkix.primitive.SubjectPublicKeyInfo)6 AlgorithmIdentifier (org.mozilla.jss.pkix.primitive.AlgorithmIdentifier)4 BIT_STRING (org.mozilla.jss.asn1.BIT_STRING)3 INTEGER (org.mozilla.jss.asn1.INTEGER)3 Calendar (java.util.Calendar)2 Date (java.util.Date)2 InternalCertificate (org.mozilla.jss.crypto.InternalCertificate)2 X509Certificate (org.mozilla.jss.crypto.X509Certificate)2 Certificate (org.mozilla.jss.pkix.cert.Certificate)2 CertificateInfo (org.mozilla.jss.pkix.cert.CertificateInfo)2 Name (org.mozilla.jss.pkix.primitive.Name)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 PublicKey (java.security.PublicKey)1 SignatureException (java.security.SignatureException)1 DSAPublicKeySpec (java.security.spec.DSAPublicKeySpec)1 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)1 RSAPublicKeySpec (java.security.spec.RSAPublicKeySpec)1 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)1