/** * Instanciate value if any from the serialized version. This instanciation must not be performed * in a dedicated classloader to avoid ClassCastException with the user's code. * * @param cl the classloader where to instanciate the object. Can be null : object is instanciated * in the default caller classloader. * @return the value if no exception has been thown. * @throws ClassNotFoundException * @throws IOException */ private Serializable instanciateValue(ClassLoader cl) throws IOException, ClassNotFoundException { if (this.serializedValue != null && this.value == null) { this.value = (Serializable) ByteToObjectConverter.ObjectStream.convert(this.serializedValue, cl); } return this.value; }
/** * Decrypts the encapsulated credentials * * @see org.ow2.proactive.authentication.crypto.KeyPairUtil#decrypt(String, String, String, * byte[]) * @param privKey the private key * @return the credential data containing the clear data:login, password and key * @throws KeyException decryption failure, malformed data */ public CredData decrypt(PrivateKey privKey) throws KeyException { byte[] data = null; byte[] aesClear = null; // recover clear AES key using the private key try { aesClear = KeyPairUtil.decrypt(this.algorithm, privKey, this.cipher, this.aes); } catch (KeyException e) { throw new KeyException("Could not decrypt symmetric key", e); } // recover clear credentials using the AES key try { data = KeyUtil.decrypt(new SecretKeySpec(aesClear, AES_ALGO), AES_CIPHER, this.data); } catch (KeyException e) { throw new KeyException("Could not decrypt data", e); } // deserialize clear credentials and obtain login & password try { return (CredData) ByteToObjectConverter.ObjectStream.convert(data); } catch (Exception e) { throw new KeyException(e.getMessage()); } }
/** * Instanciate thrown exception if any from the serialized version. This instanciation must not be * performed in a dedicated classloader to avoid ClassCastException with the user's code. * * @param cl the classloader where to instanciate the object. Can be null : object is instanciated * in the default caller classloader. * @return the exception that has been thrown if any. * @throws ClassNotFoundException * @throws IOException */ private Throwable instanciateException(ClassLoader cl) throws IOException, ClassNotFoundException { if (this.serializedException != null && this.exception == null) { this.exception = (Throwable) ByteToObjectConverter.ObjectStream.convert(this.serializedException, cl); } return this.exception; }