@BeforeClass public static void oneTimeSetup() throws CryptoException, IOException { cryptor = SymmetricCryptor.getSymmectricCryptor(TestEncryptDecrypt.class.getResource("/teiid.keystore")); //$NON-NLS-1$ }
@TeiidFunction(category=FunctionCategoryConstants.SECURITY, nullOnNull=true) public static BinaryType aes_encrypt(BinaryType dataBytes, BinaryType keyBytes) throws FunctionExecutionException { try { byte[] encryptResult = SymmetricCryptor.getSymmectricCryptor(padkey(keyBytes.getBytesDirect()), "AES", "AES/CBC/PKCS5Padding", new IvParameterSpec(iv)).encrypt(dataBytes.getBytesDirect()); //$NON-NLS-1$ //$NON-NLS-2$ return new BinaryType(encryptResult); } catch (CryptoException e) { throw new FunctionExecutionException(e); } }
byte[] symKey = new byte[keySize / 8]; System.arraycopy(hash, 0, symKey, 0, symKey.length); SymmetricCryptor sc = SymmetricCryptor.getSymmectricCryptor(symKey, cbc); sc.setUseSealedObject(useSealedObject); sc.setClassLoader(classLoader);
byte[] symKey = new byte[keySize / 8]; System.arraycopy(hash, 0, symKey, 0, symKey.length); SymmetricCryptor sc = SymmetricCryptor.getSymmectricCryptor(symKey, cbc); sc.setUseSealedObject(useSealedObject); sc.setClassLoader(classLoader);
@TeiidFunction(category=FunctionCategoryConstants.SECURITY, nullOnNull=true) public static BinaryType aes_encrypt(BinaryType dataBytes, BinaryType keyBytes) throws FunctionExecutionException { try { byte[] encryptResult = SymmetricCryptor.getSymmectricCryptor(padkey(keyBytes.getBytesDirect()), "AES", "AES/CBC/PKCS5Padding", new IvParameterSpec(iv)).encrypt(dataBytes.getBytesDirect()); //$NON-NLS-1$ //$NON-NLS-2$ return new BinaryType(encryptResult); } catch (CryptoException e) { throw new FunctionExecutionException(e); } }
@TeiidFunction(category=FunctionCategoryConstants.SECURITY, nullOnNull=true) public static BinaryType aes_decrypt(BinaryType dataBytes, BinaryType keyBytes) throws FunctionExecutionException { try { byte[] decryptResult = SymmetricCryptor.getSymmectricCryptor(padkey(keyBytes.getBytesDirect()), "AES", "AES/CBC/PKCS5Padding", new IvParameterSpec(iv)).decrypt(dataBytes.getBytesDirect()); //$NON-NLS-1$ //$NON-NLS-2$ return new BinaryType(decryptResult); } catch (CryptoException e) { throw new FunctionExecutionException(e); } }
@TeiidFunction(category=FunctionCategoryConstants.SECURITY, nullOnNull=true) public static BinaryType aes_decrypt(BinaryType dataBytes, BinaryType keyBytes) throws FunctionExecutionException { try { byte[] decryptResult = SymmetricCryptor.getSymmectricCryptor(padkey(keyBytes.getBytesDirect()), "AES", "AES/CBC/PKCS5Padding", new IvParameterSpec(iv)).decrypt(dataBytes.getBytesDirect()); //$NON-NLS-1$ //$NON-NLS-2$ return new BinaryType(decryptResult); } catch (CryptoException e) { throw new FunctionExecutionException(e); } }
@TeiidFunction(category=FunctionCategoryConstants.SECURITY, nullOnNull=true) public static BinaryType aes_encrypt(BinaryType dataBytes, BinaryType keyBytes) throws FunctionExecutionException { try { byte[] encryptResult = SymmetricCryptor.getSymmectricCryptor(padkey(keyBytes.getBytesDirect()), "AES", "AES/CBC/PKCS5Padding", new IvParameterSpec(iv)).encrypt(dataBytes.getBytesDirect()); //$NON-NLS-1$ //$NON-NLS-2$ return new BinaryType(encryptResult); } catch (CryptoException e) { throw new FunctionExecutionException(e); } }
@TeiidFunction(category=FunctionCategoryConstants.SECURITY, nullOnNull=true) public static BinaryType aes_decrypt(BinaryType dataBytes, BinaryType keyBytes) throws FunctionExecutionException { try { byte[] decryptResult = SymmetricCryptor.getSymmectricCryptor(padkey(keyBytes.getBytesDirect()), "AES", "AES/CBC/PKCS5Padding", new IvParameterSpec(iv)).decrypt(dataBytes.getBytesDirect()); //$NON-NLS-1$ //$NON-NLS-2$ return new BinaryType(decryptResult); } catch (CryptoException e) { throw new FunctionExecutionException(e); } }
@Test public void testSymmetricEncryptionWithRandomKey() throws Exception { SymmetricCryptor randomSymCryptor = SymmetricCryptor.getSymmectricCryptor(true); ArrayList test = new ArrayList(Arrays.asList(new String[] {ALPHA_L, ALPHA_U, CLEARTEXT, NUMBERS})); Object result = randomSymCryptor.sealObject(test); //ensure that we can serialize ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(result); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bais); result = ois.readObject(); ArrayList clearObject = (ArrayList)randomSymCryptor.unsealObject(result); assertEquals(test, clearObject); SymmetricCryptor cryptor1 = SymmetricCryptor.getSymmectricCryptor(randomSymCryptor.getEncodedKey(), true); clearObject = (ArrayList)cryptor1.unsealObject(result); assertEquals(test, clearObject); }