EncryCredentialManagerImpl implements EncryCredentialManager { @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()); return URLEncoder.encode(Base64Coder.encryptBASE64(sb.toString().getBytes()), "UTF-8"); } catch (Exception e) { LOGGER.log(Level.SEVERE, "encrypt data exception", e); } } return sb.toString(); }  void setKeyService(KeyService keyService); @Override EncryCredentialInfo decrypt(EncryCredential encryCredential); @Override String encrypt(EncryCredentialInfo encryCredentialInfo); @Override boolean checkEncryCredentialInfo(
			EncryCredentialInfo encryCredentialInfo);  }
@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); result = encryCredentialManager.encrypt(encryCredentialInfo); checkData(result, encryCredentialInfo); 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); }