12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- package com.kingdee.eas.custom.server;
- import java.math.BigDecimal;
- import java.security.SecureRandom;
- import java.sql.SQLException;
- import java.sql.Timestamp;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Base64;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import javax.crypto.Cipher;
- import javax.crypto.KeyGenerator;
- import javax.crypto.SecretKey;
- import javax.crypto.spec.SecretKeySpec;
- import com.kingdee.bos.BOSException;
- import com.kingdee.bos.Context;
- import com.kingdee.bos.bsf.service.app.IHRMsfService;
- import com.kingdee.eas.base.permission.UserInfo;
- import com.kingdee.eas.common.EASBizException;
- import com.kingdee.eas.util.app.ContextUtil;
- import com.kingdee.shr.empresume.util.ErrorCodeUtil;
- public class MyShrMobileNewService implements IHRMsfService{
-
- private static final String ALGORITHM = "AES";
- private static final int KEY_SIZE = 128;
-
- public Object process(Context ctx, Map param) throws EASBizException, BOSException {
- String password = ctx.getAIS();
- UserInfo currentUserInfo = ContextUtil.getCurrentUserInfo(ctx);
- HashMap map = new HashMap();
- String data = currentUserInfo.getPerson().getId().toString()+","+System.currentTimeMillis();
- String encryptedData = null;
- //¼ÓÃÜ
- try {
- encryptedData = encrypt(data, password);
- } catch (Exception e) {
- e.printStackTrace();
- }
- System.out.println("encryptedData:"+encryptedData);
- map.put("encryptedData", encryptedData);
- ErrorCodeUtil.setSuccess(map, ctx);
- return map;
- }
-
- private String encrypt(String data, String password) throws Exception {
- SecretKey key = generateKey(password);
- Cipher cipher = Cipher.getInstance(ALGORITHM);
- cipher.init(Cipher.ENCRYPT_MODE, key);
- byte[] encryptedData = cipher.doFinal(data.getBytes());
- return Base64.getEncoder().encodeToString(encryptedData);
- }
-
- private String decrypt(String encryptedData, String password) throws Exception {
- SecretKey key = generateKey(password);
- Cipher cipher = Cipher.getInstance(ALGORITHM);
- cipher.init(Cipher.DECRYPT_MODE, key);
- byte[] decryptedData = cipher.doFinal(Base64.getDecoder().decode(encryptedData));
- return new String(decryptedData);
- }
-
- private SecretKey generateKey(String password) throws Exception {
- KeyGenerator keyGenerator = KeyGenerator.getInstance(ALGORITHM);
- keyGenerator.init(KEY_SIZE, new SecureRandom(password.getBytes()));
- return new SecretKeySpec(keyGenerator.generateKey().getEncoded(), ALGORITHM);
- }
- }
|