--- /dev/null
+/*
+ * Common
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Changhyun Lee <changhyun1.lee@samsung.com>
+ * Hyeongseok Heo <hyeongseok.heo@samsung.com>
+ * BonYong Lee <bonyong.lee@samsung.com>
+ * Kangho Kim <kh5325.kim@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;
+
+import java.math.BigInteger;
+import java.security.SecureRandom;
+
+import javax.crypto.Cipher;
+import javax.crypto.KeyGenerator;
+import javax.crypto.SecretKey;
+import javax.crypto.spec.SecretKeySpec;
+
+public class AppIdGenerator {
+ final char[] PSEUDO_CHARS = { '0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
+ 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
+ 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
+ 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
+ 'y', 'z' };
+
+ final BigInteger PSEUDO_CHAR_SIZE = new BigInteger("62");
+
+ private String convertBytesToAlphaNumeric(byte in[], int size) {
+ BigInteger randomBigInt = new BigInteger(in).abs();
+ StringBuffer out = new StringBuffer(size + 1);
+
+ for (int i = 0; i < size; ++i) {
+ BigInteger[] dividedAndremainder = randomBigInt
+ .divideAndRemainder(PSEUDO_CHAR_SIZE);
+ randomBigInt = dividedAndremainder[0];
+ out.append(PSEUDO_CHARS[dividedAndremainder[1].intValue()]);
+ }
+
+ String ret = new String(out);
+ return ret;
+ }
+
+ private byte[] generateRandomBytes(int size) throws Exception {
+ SecureRandom random = new SecureRandom();
+ KeyGenerator keyGen = KeyGenerator.getInstance("AES");
+ keyGen.init(128);
+
+ byte[] bytes = new byte[size];
+ random.nextBytes(bytes);
+
+ SecretKey secretkey = keyGen.generateKey();
+ byte[] key = secretkey.getEncoded();
+ SecretKeySpec secretkeySpec = new SecretKeySpec(key, "AES");
+
+ Cipher cipher = Cipher.getInstance("AES");
+ cipher.init(Cipher.ENCRYPT_MODE, secretkeySpec);
+
+ return cipher.doFinal(bytes);
+ }
+
+ public String generate(int size) throws Exception {
+ return convertBytesToAlphaNumeric(generateRandomBytes(size), size);
+ }
+
+ public String generate() throws Exception {
+ return generate(10).toLowerCase();
+ }
+
+}
\ No newline at end of file