eec69bc0429944000a4188c279dc7c9324dce1dd
[moon.git] /
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.aaa.authn.mdsal.store;
10
11 import static org.junit.Assert.assertEquals;
12
13 import javax.xml.bind.DatatypeConverter;
14 import org.junit.Test;
15
16 public class DataEncrypterTest {
17
18     @Test
19     public void testEncrypt() {
20         DataEncrypter dataEncry = new DataEncrypter("foo_key_test");
21         String token = "foo_token_test";
22         String eToken = dataEncry.encrypt(token);
23         // check for decryption result
24         String returnToken = dataEncry.decrypt(eToken);
25         String tokenBase64 = DatatypeConverter.printBase64Binary(token.getBytes());
26         assertEquals(tokenBase64, returnToken);
27     }
28
29     @Test
30     public void testDecrypt() {
31         DataEncrypter dataEncry = new DataEncrypter("foo_key_test");
32         String eToken = "foo_etoken_test";
33         assertEquals(dataEncry.decrypt(""), null);
34         // check for encryption Tag
35         assertEquals(eToken, dataEncry.decrypt(eToken));
36     }
37
38 }