test_class.declarator: encryCredentialManager
test_class.modifier: private
test_class.original_string: private EncryCredentialManagerImpl encryCredentialManager;
test_class.type: EncryCredentialManagerImpl
test_class.var_name: encryCredentialManager
test_class.file: ki4so-common/src/test/java/com/github/ebnew/ki4so/core/authentication/EncryCredentialManagerImplTest.java
test_class.identifier: EncryCredentialManagerImplTest
test_case.body: @Test
  	public void testEncrypt() throws UnsupportedEncodingException {
  		
  		/**
  		 * 测试异常情况。
  		 */
  		Assert.assertEquals(0, encryCredentialManager.encrypt(null).length());
  		
  		
  		/**
  		 * 测试传入的参数不合法的情况。
  		 */
  		EncryCredentialInfo encryCredentialInfo = new EncryCredentialInfo();
  		KeyService keyService = Mockito.mock(KeyService.class);
  		encryCredentialManager.setKeyService(keyService);
  		String result = encryCredentialManager.encrypt(encryCredentialInfo);
  		checkData(result, encryCredentialInfo);
  		
  		
  		/**
  		 * 设置模拟服务，查询到的key为null.
  		 */
  		result = encryCredentialManager.encrypt(encryCredentialInfo);
  		checkData(result, encryCredentialInfo);
  		
  		/**
  		 * 设置模拟服务，查询到的key不是null.
  		 */
  		String keyId = "1001";
  		Ki4soKey key = new Ki4soKey();
  		key.setKeyId(keyId);
  		key.setValue("dafdasfdasfds");
  		encryCredentialInfo.setKeyId(keyId);
  		Mockito.when(keyService.findKeyByKeyId(keyId)).thenReturn(key);
  		result = encryCredentialManager.encrypt(encryCredentialInfo);
  		checkData(result, encryCredentialInfo);
  	
  		/**
  		 * 测试正常的情况。
  		 */
  		String appId = "1000";
  		String userId = "test";
  		encryCredentialInfo.setAppId(appId);
  		Date now = new Date();
  		encryCredentialInfo.setCreateTime(now);
  		encryCredentialInfo.setExpiredTime(now);
  		encryCredentialInfo.setKeyId(keyId);
  		encryCredentialInfo.setUserId(userId);
  		//加码。
  		result = encryCredentialManager.encrypt(encryCredentialInfo);
  		EncryCredential encryCredential = new EncryCredential(result);
  		//解码。
  		EncryCredentialInfo encryCredentialInfo2 = this.encryCredentialManager.decrypt(encryCredential);
  		checkEncryCredentialInfo(encryCredentialInfo, encryCredentialInfo2);
  	}
test_case.class_method_signature: EncryCredentialManagerImplTest.testEncrypt()
test_case.full_signature: @Test public void testEncrypt()
test_case.identifier: testEncrypt
test_case.invocations: assertEquals length encrypt mock setKeyService encrypt checkData encrypt checkData setKeyId setValue setKeyId thenReturn when findKeyByKeyId encrypt checkData setAppId setCreateTime setExpiredTime setKeyId setUserId encrypt decrypt checkEncryCredentialInfo
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testEncrypt()
focal_class.declarator: keyService
focal_class.modifier: private
focal_class.original_string: private KeyService keyService;
focal_class.type: KeyService
focal_class.var_name: keyService
focal_class.declarator: LOGGER = Logger.getLogger(EncryCredentialManagerImpl.class.getName())
focal_class.modifier: private static final
focal_class.original_string: private static final Logger LOGGER = Logger.getLogger(EncryCredentialManagerImpl.class.getName());
focal_class.type: Logger
focal_class.var_name: LOGGER
focal_class.file: ki4so-common/src/main/java/com/github/ebnew/ki4so/core/authentication/EncryCredentialManagerImpl.java
focal_class.identifier: EncryCredentialManagerImpl
focal_class.interfaces: implements EncryCredentialManager
focal_class.class_method_signature: EncryCredentialManagerImpl.setKeyService(KeyService keyService)
focal_class.full_signature: public void setKeyService(KeyService keyService)
focal_class.identifier: setKeyService
focal_class.modifiers: public
focal_class.parameters: (KeyService keyService)
focal_class.return: void
focal_class.signature: void setKeyService(KeyService keyService)
focal_class.class_method_signature: EncryCredentialManagerImpl.decrypt(EncryCredential encryCredential)
focal_class.full_signature: @Override public EncryCredentialInfo decrypt(EncryCredential encryCredential)
focal_class.identifier: decrypt
focal_class.modifiers: @Override public
focal_class.parameters: (EncryCredential encryCredential)
focal_class.return: EncryCredentialInfo
focal_class.signature: EncryCredentialInfo decrypt(EncryCredential encryCredential)
focal_class.class_method_signature: EncryCredentialManagerImpl.parseEncryCredential(String credential)
focal_class.full_signature: private EncryCredentialInfo parseEncryCredential(String credential)
focal_class.identifier: parseEncryCredential
focal_class.modifiers: private
focal_class.parameters: (String credential)
focal_class.return: EncryCredentialInfo
focal_class.signature: EncryCredentialInfo parseEncryCredential(String credential)
focal_class.class_method_signature: EncryCredentialManagerImpl.encrypt(EncryCredentialInfo encryCredentialInfo)
focal_class.full_signature: @Override public String encrypt(EncryCredentialInfo encryCredentialInfo)
focal_class.identifier: encrypt
focal_class.modifiers: @Override public
focal_class.parameters: (EncryCredentialInfo encryCredentialInfo)
focal_class.return: String
focal_class.signature: String encrypt(EncryCredentialInfo encryCredentialInfo)
focal_class.class_method_signature: EncryCredentialManagerImpl.encryptSensitiveInfo(EncryCredentialInfo encryCredentialInfo)
focal_class.full_signature: private String encryptSensitiveInfo(EncryCredentialInfo encryCredentialInfo)
focal_class.identifier: encryptSensitiveInfo
focal_class.modifiers: private
focal_class.parameters: (EncryCredentialInfo encryCredentialInfo)
focal_class.return: String
focal_class.signature: String encryptSensitiveInfo(EncryCredentialInfo encryCredentialInfo)
focal_class.class_method_signature: EncryCredentialManagerImpl.checkEncryCredentialInfo(
  			EncryCredentialInfo encryCredentialInfo)
focal_class.full_signature: @Override public boolean checkEncryCredentialInfo(
  			EncryCredentialInfo encryCredentialInfo)
focal_class.identifier: checkEncryCredentialInfo
focal_class.modifiers: @Override public
focal_class.parameters: (
  			EncryCredentialInfo encryCredentialInfo)
focal_class.return: boolean
focal_class.signature: boolean checkEncryCredentialInfo(
  			EncryCredentialInfo encryCredentialInfo)
focal_class.class_method_signature: EncryCredentialManagerImpl.getCurrentDate()
focal_class.full_signature: private Date getCurrentDate()
focal_class.identifier: getCurrentDate
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: Date
focal_class.signature: Date getCurrentDate()
focal_method.body: @Override
  	public String encrypt(EncryCredentialInfo encryCredentialInfo) {
  		StringBuffer sb = new StringBuffer();
  		if(encryCredentialInfo!=null){
  			try {
  				String data = encryptSensitiveInfo(encryCredentialInfo);
  				sb.append(data).append("?appId=").append(encryCredentialInfo.getAppId())
  				.append("&keyId=").append(encryCredentialInfo.getKeyId());
  				//再进行BASE64编码，避免传输错误。
  				return URLEncoder.encode(Base64Coder.encryptBASE64(sb.toString().getBytes()), "UTF-8");
  			} catch (Exception e) {
  				LOGGER.log(Level.SEVERE, "encrypt data exception", e);
  			}
  		}
  		return sb.toString();
  	}
focal_method.class_method_signature: EncryCredentialManagerImpl.encrypt(EncryCredentialInfo encryCredentialInfo)
focal_method.full_signature: @Override public String encrypt(EncryCredentialInfo encryCredentialInfo)
focal_method.identifier: encrypt
focal_method.invocations: encryptSensitiveInfo append append append append append getAppId getKeyId encode encryptBASE64 getBytes toString log toString
focal_method.modifiers: @Override public
focal_method.parameters: (EncryCredentialInfo encryCredentialInfo)
focal_method.return: String
focal_method.signature: String encrypt(EncryCredentialInfo encryCredentialInfo)