// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
package test.hibcrypt.encrypt;

import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.jasypt.hibernate3.encryptor.HibernatePBEEncryptorRegistry;

import test.hibcrypt.common.BaseTest;

/*
CREATE TABLE secretdata (
     id INTEGER NOT NULL,
     ival VARCHAR(100),
     sval VARCHAR(150),
     PRIMARY KEY(id)
);
 */

public class Test {
	public static void main(String[] args) {
        Logger.getLogger("org.hibernate").setLevel(Level.SEVERE);
        StandardPBEStringEncryptor strongEncryptor = new StandardPBEStringEncryptor();
        strongEncryptor.setPassword("ultratopsecret");
        HibernatePBEEncryptorRegistry registry = HibernatePBEEncryptorRegistry.getInstance();
        registry.registerPBEStringEncryptor("strongHibernateStringEncryptor", strongEncryptor);
        BaseTest tst = new StdTest();
        tst.execute();
	}
}

class StdTest extends BaseTest {
	@Override
	protected SessionFactory getSessionFactory() {
		Configuration cfg = new Configuration();
		File f = new File("bin/test/hibcrypt/encrypt/hibernateconfig.xml");
		cfg.configure(f);
        SessionFactory sf = cfg.buildSessionFactory();
        return sf;
	}
}
