2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.aaa.authn.mdsal.store;
11 import static org.junit.Assert.assertEquals;
13 import javax.xml.bind.DatatypeConverter;
14 import org.junit.Test;
16 public class DataEncrypterTest {
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);
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));