@Override protected void writeObject(ObjectOutput out, Object obj, Map<Object, Integer> cache, byte version) throws IOException { //uses object serialization for compatibility with legacy clients super.writeObject(out, ((BinaryType)obj).getBytesDirect(), cache, version); }
@Override protected void writeObject(ObjectOutput out, Object obj, Map<Object, Integer> cache, byte version) throws IOException { //uses object serialization for compatibility with legacy clients super.writeObject(out, ((BinaryType)obj).getBytesDirect(), cache, version); }
@TeiidFunction(category=FunctionCategoryConstants.SECURITY, nullOnNull=true) public static BinaryType sha1(BinaryType plainText) throws NoSuchAlgorithmException { return digest(plainText.getBytesDirect(), "sha-1"); //$NON-NLS-1$ }
@TeiidFunction(category=FunctionCategoryConstants.SECURITY, nullOnNull=true) public static BinaryType sha2_256(BinaryType plainText) throws NoSuchAlgorithmException { return digest(plainText.getBytesDirect(), "sha-256"); //$NON-NLS-1$ }
@TeiidFunction(category=FunctionCategoryConstants.SECURITY, nullOnNull=true) public static BinaryType sha2_512(BinaryType plainText) throws NoSuchAlgorithmException { return digest(plainText.getBytesDirect(), "sha-512"); //$NON-NLS-1$ }
@TeiidFunction(category=FunctionCategoryConstants.SECURITY, nullOnNull=true) public static BinaryType sha2_256(BinaryType plainText) throws NoSuchAlgorithmException { return digest(plainText.getBytesDirect(), "sha-256"); //$NON-NLS-1$ }
@TeiidFunction(category=FunctionCategoryConstants.SECURITY, nullOnNull=true) public static BinaryType sha2_256(BinaryType plainText) throws NoSuchAlgorithmException { return digest(plainText.getBytesDirect(), "sha-256"); //$NON-NLS-1$ }
@TeiidFunction(category=FunctionCategoryConstants.SECURITY, nullOnNull=true) public static BinaryType md5(BinaryType plainText) throws NoSuchAlgorithmException { return digest(plainText.getBytesDirect(), "md5"); //$NON-NLS-1$ }
@TeiidFunction(category=FunctionCategoryConstants.SECURITY, nullOnNull=true) public static BinaryType md5(BinaryType plainText) throws NoSuchAlgorithmException { return digest(plainText.getBytesDirect(), "md5"); //$NON-NLS-1$ }
@TeiidFunction(category=FunctionCategoryConstants.SECURITY, nullOnNull=true) public static BinaryType sha2_512(BinaryType plainText) throws NoSuchAlgorithmException { return digest(plainText.getBytesDirect(), "sha-512"); //$NON-NLS-1$ }
@TeiidFunction(category=FunctionCategoryConstants.SECURITY, nullOnNull=true) public static BinaryType sha2_512(BinaryType plainText) throws NoSuchAlgorithmException { return digest(plainText.getBytesDirect(), "sha-512"); //$NON-NLS-1$ }
@TeiidFunction(category=FunctionCategoryConstants.SECURITY, nullOnNull=true) public static BinaryType md5(BinaryType plainText) throws NoSuchAlgorithmException { return digest(plainText.getBytesDirect(), "md5"); //$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); } }
@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_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); } }
@Test public void testEncryptDecrypt() throws Exception { String key = "redhat"; //$NON-NLS-1$ String data = "jboss teiid"; //$NON-NLS-1$ BinaryType encryptedBytes = FunctionMethods.aes_encrypt(new BinaryType(data.getBytes("UTF-8")), new BinaryType(key.getBytes("UTF-8"))); //$NON-NLS-1$ //$NON-NLS-2$ BinaryType decryptedBytes = FunctionMethods.aes_decrypt(encryptedBytes, new BinaryType(key.getBytes("UTF-8"))); //$NON-NLS-1$ assertArrayEquals(data.getBytes("UTF-8"), decryptedBytes.getBytesDirect()); //$NON-NLS-1$ }
@Test public void testHashes() throws Exception { assertEquals("900150983CD24FB0D6963F7D28E17F72", PropertiesUtils.toHex(FunctionMethods.md5("abc").getBytesDirect())); assertEquals("A9993E364706816ABA3E25717850C26C9CD0D89D", PropertiesUtils.toHex(FunctionMethods.sha1("abc").getBytesDirect())); assertEquals("BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD", PropertiesUtils.toHex(FunctionMethods.sha2_256("abc").getBytesDirect())); assertEquals("DDAF35A193617ABACC417349AE20413112E6FA4E89A97EA20A9EEEE64B55D39A2192992A274FC1A836BA3C23A3FEEBBD454D4423643CE80E2A9AC94FA54CA49F", PropertiesUtils.toHex(FunctionMethods.sha2_512("abc").getBytesDirect())); }