List of usage examples for java.security Key getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:org.apache.xml.security.algorithms.implementations.IntegrityHmac.java
/** * Method engineInitSign//from ww w. j ava 2s . c o m * * @param secretKey * @throws XMLSignatureException */ protected void engineInitSign(Key secretKey) throws XMLSignatureException { if (!(secretKey instanceof SecretKey)) { String supplied = secretKey.getClass().getName(); String needed = SecretKey.class.getName(); Object exArgs[] = { supplied, needed }; throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs); } try { this.macAlgorithm.init(secretKey); } catch (InvalidKeyException ex) { throw new XMLSignatureException("empty", ex); } }
From source file:org.apache.xml.security.algorithms.implementations.IntegrityHmac.java
/** * Method engineInitSign/*from w ww . j a va 2 s . c o m*/ * * @param secretKey * @param algorithmParameterSpec * @throws XMLSignatureException */ protected void engineInitSign(Key secretKey, AlgorithmParameterSpec algorithmParameterSpec) throws XMLSignatureException { if (!(secretKey instanceof SecretKey)) { String supplied = secretKey.getClass().getName(); String needed = SecretKey.class.getName(); Object exArgs[] = { supplied, needed }; throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs); } try { this.macAlgorithm.init(secretKey, algorithmParameterSpec); } catch (InvalidKeyException ex) { throw new XMLSignatureException("empty", ex); } catch (InvalidAlgorithmParameterException ex) { throw new XMLSignatureException("empty", ex); } }
From source file:org.apache.xml.security.algorithms.implementations.SignatureBaseRSA.java
/** @inheritDoc */ protected void engineInitVerify(Key publicKey) throws XMLSignatureException { if (!(publicKey instanceof PublicKey)) { String supplied = publicKey.getClass().getName(); String needed = PublicKey.class.getName(); Object exArgs[] = { supplied, needed }; throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs); }/*w w w .j a va 2s . com*/ try { this.signatureAlgorithm.initVerify((PublicKey) publicKey); } catch (InvalidKeyException ex) { // reinstantiate Signature object to work around bug in JDK // see: http://bugs.sun.com/view_bug.do?bug_id=4953555 Signature sig = this.signatureAlgorithm; try { this.signatureAlgorithm = Signature.getInstance(signatureAlgorithm.getAlgorithm()); } catch (Exception e) { // this shouldn't occur, but if it does, restore previous // Signature if (log.isDebugEnabled()) { log.debug("Exception when reinstantiating Signature:" + e); } this.signatureAlgorithm = sig; } throw new XMLSignatureException("empty", ex); } }
From source file:org.apache.xml.security.algorithms.implementations.SignatureBaseRSA.java
/** @inheritDoc */ protected void engineInitSign(Key privateKey, SecureRandom secureRandom) throws XMLSignatureException { if (!(privateKey instanceof PrivateKey)) { String supplied = privateKey.getClass().getName(); String needed = PrivateKey.class.getName(); Object exArgs[] = { supplied, needed }; throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs); }//from w w w .j a va 2 s . co m try { this.signatureAlgorithm.initSign((PrivateKey) privateKey, secureRandom); } catch (InvalidKeyException ex) { throw new XMLSignatureException("empty", ex); } }
From source file:org.apache.xml.security.algorithms.implementations.SignatureBaseRSA.java
/** @inheritDoc */ protected void engineInitSign(Key privateKey) throws XMLSignatureException { if (!(privateKey instanceof PrivateKey)) { String supplied = privateKey.getClass().getName(); String needed = PrivateKey.class.getName(); Object exArgs[] = { supplied, needed }; throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs); }/*from w ww.j a va 2 s . c om*/ try { this.signatureAlgorithm.initSign((PrivateKey) privateKey); } catch (InvalidKeyException ex) { throw new XMLSignatureException("empty", ex); } }
From source file:org.apache.xml.security.algorithms.implementations.SignatureDSA.java
/** * @inheritDoc//from w ww . j av a 2 s. c o m */ protected void engineInitVerify(Key publicKey) throws XMLSignatureException { if (!(publicKey instanceof PublicKey)) { String supplied = publicKey.getClass().getName(); String needed = PublicKey.class.getName(); Object exArgs[] = { supplied, needed }; throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs); } try { this.signatureAlgorithm.initVerify((PublicKey) publicKey); } catch (InvalidKeyException ex) { // reinstantiate Signature object to work around bug in JDK // see: http://bugs.sun.com/view_bug.do?bug_id=4953555 Signature sig = this.signatureAlgorithm; try { this.signatureAlgorithm = Signature.getInstance(signatureAlgorithm.getAlgorithm()); } catch (Exception e) { // this shouldn't occur, but if it does, restore previous // Signature if (log.isDebugEnabled()) { log.debug("Exception when reinstantiating Signature:" + e); } this.signatureAlgorithm = sig; } throw new XMLSignatureException("empty", ex); } }
From source file:org.apache.xml.security.algorithms.implementations.SignatureECDSA.java
/** @inheritDoc */ protected void engineInitVerify(Key publicKey) throws XMLSignatureException { if (!(publicKey instanceof PublicKey)) { String supplied = publicKey.getClass().getName(); String needed = PublicKey.class.getName(); Object exArgs[] = { supplied, needed }; throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs); }//w ww . jav a2 s .co m try { this.signatureAlgorithm.initVerify((PublicKey) publicKey); } catch (InvalidKeyException ex) { // reinstantiate Signature object to work around bug in JDK // see: http://bugs.sun.com/view_bug.do?bug_id=4953555 Signature sig = this.signatureAlgorithm; try { this.signatureAlgorithm = Signature.getInstance(signatureAlgorithm.getAlgorithm()); } catch (Exception e) { // this shouldn't occur, but if it does, restore previous // Signature if (log.isDebugEnabled()) { log.debug("Exception when reinstantiating Signature:" + e); } this.signatureAlgorithm = sig; } throw new XMLSignatureException("empty", ex); } }
From source file:org.opensc.pkcs11.spi.PKCS11CipherSpi.java
@Override protected int engineGetKeySize(Key key) throws InvalidKeyException { if (key instanceof PKCS11PrivateKey) { return ((PKCS11PrivateKey) key).getKeyBits(); }/* w w w . ja v a2 s. co m*/ if (key instanceof PKCS11PublicKey) { return ((PKCS11PublicKey) key).getKeyBits(); } throw new InvalidKeyException("Invalid key class " + key.getClass()); }