Package com.github.ebnew.ki4so.core.key

Examples of com.github.ebnew.ki4so.core.key.Ki4soKey


    Assert.assertNull(keyService.findKeyByAppId(null));
    Assert.assertNull(keyService.findKeyByAppId(""));
    Assert.assertNull(keyService.findKeyByAppId("not exsited"));
   
    //测试存在数据的情况。
    Ki4soKey key = keyService.findKeyByAppId("1");
    Assert.assertNotNull(key);
    System.out.println(key);
  }
View Full Code Here


    Assert.assertNull(keyService.findKeyByKeyId(null));
    Assert.assertNull(keyService.findKeyByKeyId(""));
    Assert.assertNull(keyService.findKeyByKeyId("not exsited"));
   
    //测试存在数据的情况。
    Ki4soKey key = keyService.findKeyByKeyId("2");
    Assert.assertNotNull(key);
    System.out.println(key);
  }
View Full Code Here

        //第1个字符串不为空
        if(!StringUtils.isEmpty(items[0])){
          //使用base64解码为源字符串。
          byte[] data =  Base64Coder.decryptBASE64(items[0]);
          //查询键值。
          Ki4soKey ki4soKey = keyService.findKeyByKeyId(encryCredentialInfo.getKeyId());
          if(ki4soKey!=null){
            //使用密钥进行解密。
            byte[] origin = DESCoder.decrypt(data, ki4soKey.toSecurityKey());
            //将byte数组转换为字符串。
            String json = new String(origin);
            @SuppressWarnings("rawtypes")
            Map map = (Map)JSON.parse(json);
            if(map!=null){
View Full Code Here

    }
    if(encryCredentialInfo.getExpiredTime()!=null){
      map.put("expiredTime", encryCredentialInfo.getExpiredTime().getTime());
    }
    //查询键值。
    Ki4soKey ki4soKey = keyService.findKeyByKeyId(encryCredentialInfo.getKeyId());
    if(ki4soKey!=null){
      //查询键值。
      Key key = ki4soKey.toSecurityKey();
      if(key!=null){
        byte[] data = DESCoder.encrypt(JSON.toJSONBytes(map), key);
        //先用BASE64编码,再用URL编码。
        return Base64Coder.encryptBASE64(data);
      }
View Full Code Here

        app.setAppId(appId);
       
        App clientApp = new App();
        clientApp.setAppId(app2Id);
       
        Ki4soKey key = new Ki4soKey();
        key.setKeyId(keyId);
       
        Mockito.when(appService.findKi4soServerApp()).thenReturn(app);
        Mockito.when(appService.findAppByHost(service)).thenReturn(clientApp);
        
        KeyService keyService = Mockito.mock(KeyService.class);
View Full Code Here

  }
 
  @Test
  public void testFetchKey() throws UnsupportedEncodingException {
    KeyService keyService = Mockito.mock(KeyService.class);
    Ki4soKey ki4soKey = Mockito.mock(Ki4soKey.class);
    Mockito.when(keyService.findKeyByAppId(Mockito.anyString())).thenReturn(ki4soKey);
    keyAction.setKeyService(keyService);
    Ki4soKey result = keyAction.fetchKey("100");
    Assert.assertTrue(ki4soKey==result);
  }
View Full Code Here

  private EncryCredentialInfo buildEncryCredentialInfo(String appId, AuthenticationImpl authentication, Principal principal){
    EncryCredentialInfo encryCredentialInfo = new EncryCredentialInfo();
                if(authentication==null || principal==null){
                    return encryCredentialInfo;
                }
    Ki4soKey ki4soKey = keyService.findKeyByAppId(appId);
    if(ki4soKey==null){
      logger.log(Level.INFO, "no key for app id {0}", appId);
      throw new NoKi4soKeyException();
    }
    encryCredentialInfo.setAppId(appId);
    encryCredentialInfo.setCreateTime(authentication.getAuthenticatedDate());
    encryCredentialInfo.setUserId(principal.getId());
    encryCredentialInfo.setKeyId(ki4soKey.getKeyId());
    Date expiredTime = new Date((authentication.getAuthenticatedDate().getTime()+DURATION));
    encryCredentialInfo.setExpiredTime(expiredTime);
    return encryCredentialInfo;
  }
View Full Code Here

   
    /**
     * 设置模拟服务,查询到的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);
 
View Full Code Here

TOP

Related Classes of com.github.ebnew.ki4so.core.key.Ki4soKey

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.