Removed old deprecated classes
This commit is contained in:
parent
9de01d9922
commit
c72abfee4b
|
@ -1,38 +0,0 @@
|
|||
package org.gcube.common.encryption;
|
||||
|
||||
import java.security.Key;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Roberto Cirillo (CNR)
|
||||
*
|
||||
* @param <T> the type of the object to encrypt/decrypt
|
||||
*
|
||||
* Use {@link org.gcube.common.encryption.encrypter.Encrypter} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public interface IEncrypter<T> {
|
||||
|
||||
/**
|
||||
* Encrypts <T> with the given key or the default key
|
||||
* @param t the object to encrypt
|
||||
* @param key the key
|
||||
* @return the encrypted object
|
||||
* @throws Exception if the key is not available, invalid or the object cannot be encrypted
|
||||
|
||||
*/
|
||||
@Deprecated
|
||||
public T encrypt(T t, Key ... key) throws Exception;
|
||||
|
||||
/**
|
||||
* Decrypts <T> with the given key or the default key
|
||||
* @param t the object to decrypt
|
||||
* @param key the key
|
||||
* @return the decrypted object
|
||||
* @throws Exception if the key is not available, invalid or the object cannot be decrypted
|
||||
*/
|
||||
@Deprecated
|
||||
public T decrypt(T t, Key ... key) throws Exception;
|
||||
|
||||
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
package org.gcube.common.encryption;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import java.security.Key;
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
|
||||
/**
|
||||
* Encrypter for {@link String} objects
|
||||
* @author Manuele Simi (CNR)
|
||||
* @author Roberto Cirillo (ISTI - CNR)
|
||||
* @author Lucio Lelii (ISTI - CNR)
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*
|
||||
* Use {@link org.gcube.common.encryption.encrypter.StringEncrypter} instead
|
||||
*
|
||||
*/
|
||||
@Deprecated
|
||||
public class StringEncrypter implements IEncrypter<String>{
|
||||
|
||||
private static StringEncrypter singleton;
|
||||
|
||||
StringEncrypter() {}
|
||||
|
||||
/**
|
||||
* Gets the Encrypter for {@link String}
|
||||
* @return the encrypter
|
||||
*/
|
||||
public static StringEncrypter getEncrypter(){
|
||||
if (singleton == null) {
|
||||
singleton = new StringEncrypter();
|
||||
}
|
||||
return singleton;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypts the string with the given key
|
||||
* @param key the key for encrypting
|
||||
* @return the encrypted string in a Base64 encoding
|
||||
* @throws Exception
|
||||
*/
|
||||
@Deprecated
|
||||
public String encrypt(String string, Key ... key) throws Exception {
|
||||
Key ekey = (key!=null && key.length>0)? key[0] : SymmetricKey.getKey();
|
||||
Cipher cipher = Cipher.getInstance(ekey.getAlgorithm());
|
||||
cipher.init(Cipher.ENCRYPT_MODE, ekey);
|
||||
// return new String(Base64.encode(cipher.doFinal(string.getBytes())));
|
||||
return new String(DatatypeConverter.printBase64Binary((cipher.doFinal(string.getBytes()))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypts the string with the given key
|
||||
* @param key the key to use for decrypting
|
||||
* @return the decrypted string
|
||||
* @throws Exception
|
||||
*/
|
||||
@Deprecated
|
||||
public String decrypt(String string, Key ... key) throws Exception {
|
||||
Key dkey = (key!=null && key.length>0)? key[0] : SymmetricKey.getKey();
|
||||
Cipher cipher = Cipher.getInstance(dkey.getAlgorithm());
|
||||
cipher.init(Cipher.DECRYPT_MODE, dkey);
|
||||
// return new String(cipher.doFinal(Base64.decode(string.getBytes())));
|
||||
return new String(cipher.doFinal(DatatypeConverter.parseBase64Binary(string)));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
package org.gcube.common.encryption;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class StringEncrypterTest {
|
||||
|
||||
static java.security.Key key;
|
||||
static String toEnc = "String to encrypt";
|
||||
static String encString;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
SecretManagerProvider.instance.set(new TestSecret("/gcube/devsec"));
|
||||
key = SymmetricKey.getKey();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void testEncryptDecrypt() {
|
||||
try {
|
||||
System.out.println("---- STRING ENCRYPTION ----");
|
||||
System.out.println("String to encrypt " + toEnc);
|
||||
encString = StringEncrypter.getEncrypter().encrypt(toEnc,key);
|
||||
System.out.println("Encrypted string : " + encString);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("failed to encrypt");
|
||||
}
|
||||
try {
|
||||
System.out.println("---- STRING DECRYPTION ----");
|
||||
System.out.println("String to decrypt " + encString);
|
||||
String decryptedString = StringEncrypter.getEncrypter().decrypt(encString,key);
|
||||
System.out.println("Decrypted string : " + decryptedString);
|
||||
Assert.assertTrue(decryptedString.compareTo(toEnc)==0);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("failed to decrypt");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue