DB update script 6

This commit is contained in:
jendib 2013-08-20 18:55:49 +02:00
parent 00b00f0d0c
commit 906de329ae
7 changed files with 17 additions and 3 deletions

View File

@ -14,6 +14,8 @@ import javax.crypto.spec.PBEKeySpec;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import com.google.common.base.Strings;
/**
* Encryption utilities.
*
@ -47,6 +49,9 @@ public class EncryptionUtil {
*/
public static InputStream encryptStream(InputStream is, String privateKey) throws Exception {
checkBouncyCastleProvider();
if (Strings.isNullOrEmpty(privateKey)) {
throw new IllegalArgumentException("The private key is null or empty");
}
return new CipherInputStream(is, getCipher(privateKey, Cipher.ENCRYPT_MODE));
}

View File

@ -1 +1 @@
db.version=5
db.version=6

View File

@ -0,0 +1,2 @@
alter table T_USER add column USE_PRIVATEKEY_C varchar(100) default '' not null;
update T_CONFIG set CFG_VALUE_C='6' where CFG_ID_C='DB_VERSION';

View File

@ -21,6 +21,7 @@ public class TestJpa extends BaseTransactionalTest {
user.setEmail("toto@docs.com");
user.setLocaleId("fr");
user.setRoleId("admin");
user.setPrivateKey("AwesomePrivateKey");
String id = userDao.create(user);
TransactionUtil.commit();

View File

@ -31,6 +31,12 @@ public class TestEncryptUtil {
@Test
public void encryptStreamTest() throws Exception {
try {
EncryptionUtil.encryptStream(this.getClass().getResourceAsStream("/file/udhr.pdf"), "");
Assert.fail();
} catch (IllegalArgumentException e) {
// NOP
}
InputStream inputStream = EncryptionUtil.encryptStream(this.getClass().getResourceAsStream("/file/udhr.pdf"), pk);
byte[] encryptedData = Streams.readAll(inputStream);
byte[] assertData = Streams.readAll(this.getClass().getResourceAsStream("/file/udhr_encrypted.pdf"));

View File

@ -1,3 +1,3 @@
api.current_version=${project.version}
api.min_version=1.0
db.version=5
db.version=6

View File

@ -1,3 +1,3 @@
api.current_version=${project.version}
api.min_version=1.0
db.version=5
db.version=6