re base code
[sdc.git] / security-utils / src / test / java / org / openecomp / sdc / security / SecurityUtilTest.java
1 package org.openecomp.sdc.security;
2
3 import org.junit.Test;
4
5 import java.util.Base64;
6
7 import static org.junit.Assert.assertEquals;
8 import static org.junit.Assert.assertNotEquals;
9
10 public class SecurityUtilTest {
11
12     @Test
13     public void encryptDecryptAES128() throws Exception {
14         String data = "decrypt SUCCESS!!";
15         String encrypted = SecurityUtil.INSTANCE.encrypt(data).left().value();
16         assertNotEquals( data, encrypted );
17         byte[] decryptMsg = Base64.getDecoder().decode(encrypted);
18         assertEquals( SecurityUtil.INSTANCE.decrypt( decryptMsg , false ).left().value() ,data );
19         assertEquals( SecurityUtil.INSTANCE.decrypt( encrypted.getBytes() , true ).left().value() ,data );
20     }
21
22     @Test
23     public void obfuscateKey() throws Exception {
24         String key = "abcdefghij123456";
25         String expectedkey = "********ij123456";
26         String obfuscated = SecurityUtil.INSTANCE.obfuscateKey( key );
27         System.out.println( obfuscated );
28         assertEquals( obfuscated , expectedkey );
29     }
30 }