Sync Integ to Master
[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 import java.util.Base64;
5 import static org.junit.Assert.*;
6
7 public class SecurityUtilTest {
8
9     @Test
10     public void encryptDecryptAES128() throws Exception {
11         String data = "decrypt SUCCESS!!";
12         String encrypted = SecurityUtil.INSTANCE.encrypt(data).left().value();
13         assertNotEquals( data, encrypted );
14         byte[] decryptMsg = Base64.getDecoder().decode(encrypted);
15         assertEquals( SecurityUtil.INSTANCE.decrypt( decryptMsg , false ).left().value() ,data );
16         assertEquals( SecurityUtil.INSTANCE.decrypt( encrypted.getBytes() , true ).left().value() ,data );
17     }
18
19     @Test
20     public void obfuscateKey() throws Exception {
21         String key = "abcdefghij123456";
22         String expectedkey = "********ij123456";
23         String obfuscated = SecurityUtil.INSTANCE.obfuscateKey( key );
24         System.out.println( obfuscated );
25         assertEquals( obfuscated , expectedkey );
26     }
27 }