mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
Merged 5.2.N (5.2.1) to HEAD (5.2)
125783 rmunteanu: Merged 5.1.N (5.1.2) to 5.2.N (5.2.1) 125605 rmunteanu: Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2) 125498 slanglois: MNT-16155 Update source headers - remove svn:eol-style property on Java and JSP source files git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@127809 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,80 +1,80 @@
|
||||
package org.alfresco.encryption;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.security.AlgorithmParameters;
|
||||
import java.security.KeyException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.util.Pair;
|
||||
|
||||
/**
|
||||
* @since 4.0
|
||||
*/
|
||||
public class EncryptorTest extends TestCase
|
||||
{
|
||||
private DefaultEncryptor encryptor;
|
||||
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
encryptor = new DefaultEncryptor(
|
||||
KeyStoreKeyProviderTest.getTestKeyStoreProvider(),
|
||||
"DESede/CBC/PKCS5Padding",
|
||||
null);
|
||||
encryptor.init(); // Not currently necessary
|
||||
}
|
||||
|
||||
public void testBasicBytes_NoKey()
|
||||
{
|
||||
byte[] bytes = new byte[] {11, 12, 13};
|
||||
|
||||
Pair<byte[], AlgorithmParameters> encryptedPair = encryptor.encrypt("fluff", null, bytes);
|
||||
byte[] decrypted = encryptor.decrypt(
|
||||
"fluff",
|
||||
encryptedPair.getSecond(),
|
||||
encryptedPair.getFirst());
|
||||
assertTrue("Encryption round trip failed. ", Arrays.equals(bytes, decrypted));
|
||||
}
|
||||
|
||||
public void testBasicBytes_WithKey()
|
||||
{
|
||||
byte[] bytes = new byte[] {11, 12, 13};
|
||||
|
||||
Pair<byte[], AlgorithmParameters> encryptedPair = encryptor.encrypt("mykey1", null, bytes);
|
||||
byte[] decrypted = encryptor.decrypt(
|
||||
"mykey1",
|
||||
encryptedPair.getSecond(),
|
||||
encryptedPair.getFirst());
|
||||
assertTrue("Encryption round trip failed. ", Arrays.equals(bytes, decrypted));
|
||||
}
|
||||
|
||||
public void testBasicObject()
|
||||
{
|
||||
Object testObject = " This is a string, but will be serialized ";
|
||||
|
||||
Pair<byte[], AlgorithmParameters> encryptedPair = encryptor.encryptObject("mykey2", null, testObject);
|
||||
Object output = encryptor.decryptObject(
|
||||
"mykey2",
|
||||
encryptedPair.getSecond(),
|
||||
encryptedPair.getFirst());
|
||||
assertEquals("Encryption round trip failed. ", testObject, output);
|
||||
}
|
||||
|
||||
public void testSealedObject()
|
||||
{
|
||||
Serializable testObject = " This is a string, but will be serialized ";
|
||||
|
||||
Serializable sealedObject = encryptor.sealObject("mykey2", null, testObject);
|
||||
try
|
||||
{
|
||||
Object output = encryptor.unsealObject("mykey2", sealedObject);
|
||||
assertEquals("Encryption round trip failed. ", testObject, output);
|
||||
}
|
||||
catch(KeyException e)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.alfresco.encryption;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.security.AlgorithmParameters;
|
||||
import java.security.KeyException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.util.Pair;
|
||||
|
||||
/**
|
||||
* @since 4.0
|
||||
*/
|
||||
public class EncryptorTest extends TestCase
|
||||
{
|
||||
private DefaultEncryptor encryptor;
|
||||
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
encryptor = new DefaultEncryptor(
|
||||
KeyStoreKeyProviderTest.getTestKeyStoreProvider(),
|
||||
"DESede/CBC/PKCS5Padding",
|
||||
null);
|
||||
encryptor.init(); // Not currently necessary
|
||||
}
|
||||
|
||||
public void testBasicBytes_NoKey()
|
||||
{
|
||||
byte[] bytes = new byte[] {11, 12, 13};
|
||||
|
||||
Pair<byte[], AlgorithmParameters> encryptedPair = encryptor.encrypt("fluff", null, bytes);
|
||||
byte[] decrypted = encryptor.decrypt(
|
||||
"fluff",
|
||||
encryptedPair.getSecond(),
|
||||
encryptedPair.getFirst());
|
||||
assertTrue("Encryption round trip failed. ", Arrays.equals(bytes, decrypted));
|
||||
}
|
||||
|
||||
public void testBasicBytes_WithKey()
|
||||
{
|
||||
byte[] bytes = new byte[] {11, 12, 13};
|
||||
|
||||
Pair<byte[], AlgorithmParameters> encryptedPair = encryptor.encrypt("mykey1", null, bytes);
|
||||
byte[] decrypted = encryptor.decrypt(
|
||||
"mykey1",
|
||||
encryptedPair.getSecond(),
|
||||
encryptedPair.getFirst());
|
||||
assertTrue("Encryption round trip failed. ", Arrays.equals(bytes, decrypted));
|
||||
}
|
||||
|
||||
public void testBasicObject()
|
||||
{
|
||||
Object testObject = " This is a string, but will be serialized ";
|
||||
|
||||
Pair<byte[], AlgorithmParameters> encryptedPair = encryptor.encryptObject("mykey2", null, testObject);
|
||||
Object output = encryptor.decryptObject(
|
||||
"mykey2",
|
||||
encryptedPair.getSecond(),
|
||||
encryptedPair.getFirst());
|
||||
assertEquals("Encryption round trip failed. ", testObject, output);
|
||||
}
|
||||
|
||||
public void testSealedObject()
|
||||
{
|
||||
Serializable testObject = " This is a string, but will be serialized ";
|
||||
|
||||
Serializable sealedObject = encryptor.sealObject("mykey2", null, testObject);
|
||||
try
|
||||
{
|
||||
Object output = encryptor.unsealObject("mykey2", sealedObject);
|
||||
assertEquals("Encryption round trip failed. ", testObject, output);
|
||||
}
|
||||
catch(KeyException e)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user