List of usage examples for org.springframework.security.util InMemoryResource InMemoryResource
public InMemoryResource(byte[] source)
From source file:cherry.foundation.crypto.AESCryptoSupportTest.java
@Test public void testDefault() throws Exception { AESCryptoSupport crypto = new AESCryptoSupport(); crypto.setSecretKeyResource(new InMemoryResource(RandomUtils.nextBytes(16))); crypto.afterPropertiesSet();//from ww w . j a va2s .c om for (int i = 0; i < 100; i++) { byte[] plain = RandomUtils.nextBytes(1024); byte[] enc = crypto.encrypt(plain); byte[] dec = crypto.decrypt(enc); assertThat(dec, is(plain)); } }
From source file:cherry.foundation.crypto.AESDeterministicCryptoSupportTest.java
@Test public void testDefault() throws Exception { AESDeterministicCryptoSupport crypto = new AESDeterministicCryptoSupport(); crypto.setSecretKeyResource(new InMemoryResource(RandomUtils.nextBytes(16))); crypto.setInitVectorResource(new InMemoryResource(RandomUtils.nextBytes(16))); crypto.afterPropertiesSet();/*from w ww . j a va 2 s .c om*/ for (int i = 0; i < 100; i++) { byte[] plain = RandomUtils.nextBytes(1024); byte[] enc = crypto.encrypt(plain); byte[] dec = crypto.decrypt(enc); assertThat(dec, is(plain)); } }
From source file:cherry.foundation.crypto.AESCryptoSupportTest.java
@Test public void testCBC() throws Exception { AESCryptoSupport crypto = new AESCryptoSupport(); crypto.setAlgorithm("AES/CBC/PKCS5Padding"); crypto.setSecretKeyResource(new InMemoryResource(RandomUtils.nextBytes(16))); crypto.afterPropertiesSet();//from w w w . java2s . c o m for (int i = 0; i < 100; i++) { byte[] plain = RandomUtils.nextBytes(1024); byte[] enc = crypto.encrypt(plain); byte[] dec = crypto.decrypt(enc); assertThat(dec, is(plain)); } }
From source file:cherry.foundation.crypto.RSASignatureSupportTest.java
private RSASignatureSupport createCrypto() throws Exception { KeyPairGenerator keygen = KeyPairGenerator.getInstance("RSA"); keygen.initialize(2048);/*from ww w .ja v a2s. c o m*/ KeyPair key = keygen.generateKeyPair(); RSASignatureSupport crypto = new RSASignatureSupport(); crypto.setAlgorithm("SHA256withRSA"); crypto.setPublicKeyResource(new InMemoryResource(key.getPublic().getEncoded())); crypto.setPrivateKeyResource(new InMemoryResource(key.getPrivate().getEncoded())); crypto.afterPropertiesSet(); return crypto; }
From source file:cherry.foundation.crypto.RSACryptoSupportTest.java
private RSACryptoSupport createCrypto() throws Exception { KeyPairGenerator keygen = KeyPairGenerator.getInstance("RSA"); keygen.initialize(2048);/*from ww w .j a va 2 s . co m*/ KeyPair key = keygen.generateKeyPair(); RSACryptoSupport crypto = new RSACryptoSupport(); crypto.setAlgorithm("RSA/ECB/PKCS1Padding"); crypto.setPublicKeyResource(new InMemoryResource(key.getPublic().getEncoded())); crypto.setPrivateKeyResource(new InMemoryResource(key.getPrivate().getEncoded())); crypto.afterPropertiesSet(); return crypto; }
From source file:cherry.foundation.crypto.AESDeterministicCryptoSupportTest.java
@Test public void testCBC() throws Exception { AESDeterministicCryptoSupport crypto = new AESDeterministicCryptoSupport(); crypto.setAlgorithm("AES/CBC/PKCS5Padding"); crypto.setSecretKeyResource(new InMemoryResource(RandomUtils.nextBytes(16))); crypto.setInitVectorResource(new InMemoryResource(RandomUtils.nextBytes(16))); crypto.afterPropertiesSet();//from w w w . j a va2 s .c o m for (int i = 0; i < 100; i++) { byte[] plain = RandomUtils.nextBytes(1024); byte[] enc = crypto.encrypt(plain); byte[] dec = crypto.decrypt(enc); assertThat(dec, is(plain)); } }
From source file:cherry.foundation.sql.SqlLoaderImplTest.java
() throws IOException { Resource resource = new InMemoryResource("-- NAME: TEST00\nSELECT 0 FROM dual;"); Map<String, String> sqlmap = sqlLoader.load(resource); assertEquals("SELECT 0 FROM dual", sqlmap.get("TEST00")); }
From source file:cherry.foundation.crypto.AESCryptoSupportTest.java
@Test public void testUsingKeyCipherHelper() throws Exception { byte[] key = RandomUtils.nextBytes(16); AESCryptoSupport crypto0 = new AESCryptoSupport(); crypto0.setSecretKeyResource(new InMemoryResource(key)); crypto0.afterPropertiesSet();// ww w.jav a 2s. c o m AESCryptoSupport keyCrypto = new AESCryptoSupport(); keyCrypto.setSecretKeyResource(new InMemoryResource(RandomUtils.nextBytes(16))); keyCrypto.afterPropertiesSet(); AESCryptoSupport crypto1 = new AESCryptoSupport(); crypto1.setKeyCrypto(keyCrypto); crypto1.setSecretKeyResource(new InMemoryResource(keyCrypto.encrypt(key))); crypto1.afterPropertiesSet(); for (int i = 0; i < 100; i++) { byte[] plain = RandomUtils.nextBytes(1024); byte[] enc0 = crypto0.encrypt(plain); byte[] enc1 = crypto1.encrypt(plain); assertThat(enc1, is(not(enc0))); byte[] dec0 = crypto0.decrypt(enc0); byte[] dec1 = crypto1.decrypt(enc1); assertThat(dec0, is(plain)); assertThat(dec1, is(plain)); } }
From source file:cherry.foundation.crypto.AESDeterministicCryptoSupportTest.java
@Test public void testECB() throws Exception { AESDeterministicCryptoSupport crypto = new AESDeterministicCryptoSupport(); crypto.setAlgorithm("AES/ECB/PKCS5Padding"); crypto.setSecretKeyResource(new InMemoryResource(RandomUtils.nextBytes(16))); crypto.afterPropertiesSet();/* www . j av a2s. c o m*/ for (int i = 0; i < 100; i++) { byte[] plain = RandomUtils.nextBytes(1024); byte[] enc = crypto.encrypt(plain); byte[] dec = crypto.decrypt(enc); assertThat(dec, is(plain)); } }