blob: 6a47434efc6fb6c705dc25ec65eb4d58ad96ff3c [file] [log] [blame]
Yuli Shlosberga4eeb112019-01-07 16:23:36 +02001package org.onap.sdc.security;
2
3import org.junit.Test;
4
5import java.util.Base64;
6
7import static org.junit.Assert.assertEquals;
8import static org.junit.Assert.assertNotEquals;
9
10public class SecurityUtilTest {
11
12 @Test
13 public void encryptDecryptAES128() {
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() {
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}