--- /dev/null
+/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Ho Namkoong <ho.namkoong@samsung.com>
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+
+package org.tizen.common.util;
+
+import javax.crypto.Cipher;
+import javax.crypto.SecretKey;
+import javax.crypto.SecretKeyFactory;
+import javax.crypto.spec.DESedeKeySpec;
+
+import org.tizen.common.util.log.Logger;
+
+import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
+
+/**
+ * PluginUtil
+ *
+ * This is a util class for encrypting and decrypting plain texts.
+ *
+ * @author Ho Namkoong{@literal <ho.namkoong@samsung.com>} (S-Core)
+ */
+public class CipherUtil {
+
+ private static final String password = "ANYLINKhijklmnopqrstuvwx";
+ private static SecretKey SECRETE_KEY;
+ private static Cipher DES_CIPHER;
+ private static final String ALGORITHM = "DESede";
+
+ static {
+ try {
+ byte key[] = password.getBytes();
+ DESedeKeySpec desKeySpec = new DESedeKeySpec(key);
+ SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ALGORITHM);
+ SECRETE_KEY = keyFactory.generateSecret(desKeySpec);
+
+ DES_CIPHER = Cipher.getInstance(ALGORITHM + "/ECB/PKCS5Padding");
+ } catch (Throwable t) {
+ Logger.error("Exception occurred while creating secrete key", t);
+ }
+ }
+
+ private static byte[] decryptByDES(byte[] bytes) throws Exception{
+ DES_CIPHER.init(Cipher.DECRYPT_MODE, SECRETE_KEY);
+
+ return DES_CIPHER.doFinal(bytes);
+ }
+
+ private static byte[] encryptByDES(String s) throws Exception {
+ DES_CIPHER.init(Cipher.ENCRYPT_MODE, SECRETE_KEY);
+
+ return DES_CIPHER.doFinal(s.getBytes());
+ }
+
+ /**
+ * Decrypt cipher message
+ *
+ * @param s cipher message which will be decrypted.
+ * @return decrypted plain text.
+ * @author Ho Namkoong {@literal <ho.namkoong@samsung.com>} (S-Core)
+ */
+ public static String getDecryptedString(String s) throws Exception {
+ return new String(decryptByDES(Base64.decode(s)));
+ }
+
+ /**
+ * Encrypt plain text
+ *
+ * @param s plain text which will be encrypted.
+ * @return encrypted cipher text.
+ * @author Ho Namkoong {@literal <ho.namkoong@samsung.com>} (S-Core)
+ */
+ public static String getEncryptedString(String s) throws Exception {
+ return new String(Base64.encode(encryptByDES(s)));
+ }
+}
--- /dev/null
+/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Ho Namkoong <ho.namkoong@samsung.com>
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+
+package org.tizen.common.util;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * CipherUtilTest
+ *
+ * Test case for {@link CipherUtil}
+ *
+ * @author Ho Namkoong{@literal <ho.namkoong@samsung.com>} (S-Core)
+ *
+ * @see CipherUtil
+ */
+public class CipherUtilTest {
+
+ /**
+ * Original password list which should be encrypted
+ */
+ private static final String[] passList = {"1234", "wiehj2j3hxcgf", "0932hsdhgfasdf", "kj2h3ejaswdas"};
+
+ /**
+ * Encrypted password
+ */
+ private String[] encryptedPassList = new String[passList.length];
+
+ /**
+ * Decrypted password
+ */
+ private String[] decryptedPassList = new String[passList.length];
+
+ /**
+ * Test {@link CipherUtil#getEncryptedString(String)}
+ *
+ * @throws Exception in case of failure in test
+ *
+ * @see CipherUtil#getEncryptedString(String)
+ */
+ private void test_getEncryptedBase64String() throws Exception {
+ for (int i = 0; i < passList.length; i++) {
+ encryptedPassList[i] = CipherUtil.getEncryptedString(passList[i]);
+ Assert.assertNotNull(encryptedPassList[i]);
+ }
+ }
+
+ /**
+ * Test {@link CipherUtil#getDecryptedString(String)}
+ *
+ * @throws Exception in case of failure in test
+ *
+ * @see CipherUtil#getDecryptedString(String)
+ */
+ private void test_getDecryptedString() throws Exception {
+ for(int i=0; i<encryptedPassList.length;i++) {
+ decryptedPassList[i] = CipherUtil.getDecryptedString(encryptedPassList[i]);
+ Assert.assertNotNull(decryptedPassList[i]);
+ }
+ }
+
+ @Test
+ public void test_cipher() throws Exception {
+ this.test_getEncryptedBase64String();
+ this.test_getDecryptedString();
+
+ for (int i = 0; i < passList.length; i++) {
+ Assert.assertTrue(passList[i].equals(decryptedPassList[i]));
+ }
+ }
+}