当前位置: 首页>>代码示例>>Java>>正文


Java MacProvider.generateKey方法代码示例

本文整理汇总了Java中io.jsonwebtoken.impl.crypto.MacProvider.generateKey方法的典型用法代码示例。如果您正苦于以下问题:Java MacProvider.generateKey方法的具体用法?Java MacProvider.generateKey怎么用?Java MacProvider.generateKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.jsonwebtoken.impl.crypto.MacProvider的用法示例。


在下文中一共展示了MacProvider.generateKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testExpiredToken

import io.jsonwebtoken.impl.crypto.MacProvider; //导入方法依赖的package包/类
@Test
public void testExpiredToken() {

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    calendar.add(Calendar.SECOND, 1);

    Key key = MacProvider.generateKey();

    // new KeyPair("publickey","privatekey")
    String token = TokenUtil.getJWTString("Phil", new String[]{"user"}, 11, calendar.getTime(), key);
    assertNotNull(token);
    try {
        Thread.sleep(1000L * 3L);                 //1000 milliseconds is one second.
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
    }

    assertEquals("Token should have expired", false, TokenUtil.isValid(token, key));
}
 
开发者ID:psenger,项目名称:Jersey2-Security-JWT,代码行数:21,代码来源:TokenUtilTest.java

示例2: testNonExpiredToken

import io.jsonwebtoken.impl.crypto.MacProvider; //导入方法依赖的package包/类
@Test
public void testNonExpiredToken() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    calendar.add(Calendar.MINUTE, 15);

    Key key = MacProvider.generateKey();

    // new KeyPair("publickey","privatekey")
    String token = TokenUtil.getJWTString("Phil", new String[]{"user"}, 12, calendar.getTime(), key);
    assertNotNull(token);
    try {
        Thread.sleep(1000L * 2L);                 //1000 milliseconds is one second.
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
    }

    assertEquals("Token should have been valid", true, TokenUtil.isValid(token, key));
}
 
开发者ID:psenger,项目名称:Jersey2-Security-JWT,代码行数:20,代码来源:TokenUtilTest.java

示例3: builder

import io.jsonwebtoken.impl.crypto.MacProvider; //导入方法依赖的package包/类
public static JwtBuilder builder(KeyEncrypt keyEncrypt) throws KeyOperationException {
    SecretKey secretKey = MacProvider.generateKey(SignatureAlgorithm.HS256);
    byte[] encryptedKey = keyEncrypt.encrypt(secretKey.getEncoded());

    return Jwts.builder()
            .setHeaderParam("kid", DatatypeConverter.printBase64Binary(encryptedKey))
            .signWith(SignatureAlgorithm.HS256, secretKey);
}
 
开发者ID:julianghionoiu,项目名称:kms-jwt,代码行数:9,代码来源:JWTEncoder.java

示例4: testSigninService

import io.jsonwebtoken.impl.crypto.MacProvider; //导入方法依赖的package包/类
@Test
	public void testSigninService() {

		UserSigninReq reqObj = new UserSigninReq();
		// reqObj.setAppName("samyh");
		// reqObj.setDeviceType("android");
		// reqObj.setVersion("0.0.1");
//		reqObj.setUserPhone("13900000014");
		reqObj.setPassword("123456789");
		reqObj.setDeviceInfo("XXXXXXXXXXX");

		String jsonReq = JSON.toJSONString(reqObj);

		logger.info("Reuqest json String:" + jsonReq);

		String url = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/user/signin.json").build().toUriString();

		logger.info("Request URL:" + url);

		Key key = MacProvider.generateKey();
		String s = createJWT(key, jsonReq);
		logger.info("jwt:" + s);

		String str = decodeJWT(key, s);
		logger.info("jwt:" + str);

		MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
		params.add("jsonReq", jsonReq);
		String resp = restTemplate.postForObject(url, params, String.class);

		logger.info("ResponseBody:" + resp);

		assertEquals(jsonReq, str);
	}
 
开发者ID:booleguo,项目名称:sam-elle,代码行数:35,代码来源:UserSigninTest.java

示例5: Application

import io.jsonwebtoken.impl.crypto.MacProvider; //导入方法依赖的package包/类
public Application() {
        this(new BookDao(), new UserDao(), MacProvider.generateKey());

        User user = new User();
        user.setUsername("ironman");
        user.setEmail("[email protected]");
        user.setRoles(new String[]{"user", "admin"});
        user.setHashedPassword("password");
        this.getUserDao().addUser(user);

        Book book1 = new Book();
//        book1.setId("1");
        book1.setTitle("The Sharp Sliver");
        book1.setAuthor("Clementine Green");
        book1.setIsbn("1234");
        book1.setPublished(new Date());

        Book book2 = new Book();
//        book2.setId("2");
        book2.setTitle("Edge of Darkness");
        book2.setAuthor("Francisco Fry");
        book2.setIsbn("1234");
        book2.setPublished(new Date());

        this.getBookDao().addBook(book1);
        // books.put(book1.getId(), book1);
        this.getBookDao().addBook(book2);
        // books.put(book2.getId(), book2);
    }
 
开发者ID:psenger,项目名称:Jersey2-Security-JWT,代码行数:30,代码来源:Application.java

示例6: configure

import io.jsonwebtoken.impl.crypto.MacProvider; //导入方法依赖的package包/类
protected javax.ws.rs.core.Application configure() {
    enable(TestProperties.LOG_TRAFFIC);
    enable(TestProperties.DUMP_ENTITY);
    final BookDao bookDao = new BookDao();
    final UserDao userDao = new UserDao();
    userDao.addUser(AdminUser);
    userDao.addUser(NormalUser);
    book1Id = bookDao.addBook(book1).getId();
    book2Id = bookDao.addBook(book2).getId();
    final Key key = MacProvider.generateKey();
    return new com.sample.Application(bookDao, userDao, key);
}
 
开发者ID:psenger,项目名称:Jersey2-Security-JWT,代码行数:13,代码来源:BookResourceTest.java

示例7: configure

import io.jsonwebtoken.impl.crypto.MacProvider; //导入方法依赖的package包/类
protected javax.ws.rs.core.Application configure() {
    userDao = new UserDao();
    bookDao = new BookDao();
    enable(TestProperties.LOG_TRAFFIC);
    enable(TestProperties.DUMP_ENTITY);
    final Key key = MacProvider.generateKey();
    User user = userDao.addUser(buildUser(2L, "bob", "[email protected]com", new String[]{"user"}, "aPassW0rd"));
    return new Application(bookDao, userDao, key);
}
 
开发者ID:psenger,项目名称:Jersey2-Security-JWT,代码行数:10,代码来源:AuthenticationResourceTest.java

示例8: testGetJWTString_invalidUserName

import io.jsonwebtoken.impl.crypto.MacProvider; //导入方法依赖的package包/类
@Test(expected = NullPointerException.class)
public void testGetJWTString_invalidUserName() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    calendar.add(Calendar.MINUTE, 15);
    String username = null;
    String[] roles = new String[]{"user"};
    int version = 0;
    Date expires = calendar.getTime();
    Key key = MacProvider.generateKey();
    TokenUtil.getJWTString(username, roles, version, expires, key);
}
 
开发者ID:psenger,项目名称:Jersey2-Security-JWT,代码行数:13,代码来源:TokenUtilTest.java

示例9: testGetJWTString_invalidRoles

import io.jsonwebtoken.impl.crypto.MacProvider; //导入方法依赖的package包/类
@Test(expected = NullPointerException.class)
public void testGetJWTString_invalidRoles() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    calendar.add(Calendar.MINUTE, 15);
    String username = "Bob";
    String[] roles = null;
    int version = 0;
    Date expires = calendar.getTime();
    Key key = MacProvider.generateKey();
    TokenUtil.getJWTString(username, roles, version, expires, key);
}
 
开发者ID:psenger,项目名称:Jersey2-Security-JWT,代码行数:13,代码来源:TokenUtilTest.java

示例10: testGetJWTString_invalidExpires

import io.jsonwebtoken.impl.crypto.MacProvider; //导入方法依赖的package包/类
@Test(expected = NullPointerException.class)
public void testGetJWTString_invalidExpires() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    calendar.add(Calendar.MINUTE, 15);
    String username = "Bob";
    String[] roles = new String[]{"user"};
    int version = 0;
    Date expires = null;
    Key key = MacProvider.generateKey();
    TokenUtil.getJWTString(username, roles, version, expires, key);
}
 
开发者ID:psenger,项目名称:Jersey2-Security-JWT,代码行数:13,代码来源:TokenUtilTest.java

示例11: testGetVersionGood

import io.jsonwebtoken.impl.crypto.MacProvider; //导入方法依赖的package包/类
@Test
public void testGetVersionGood() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    calendar.add(Calendar.MINUTE, 15);
    String username = "Bob";
    String[] roles = new String[]{"user"};
    int version = 3;
    Date expires = calendar.getTime();
    Key key = MacProvider.generateKey();
    String jwtString = TokenUtil.getJWTString(username, roles, version, expires, key);
    int version1 = TokenUtil.getVersion(jwtString, key);
    assertEquals(version, version1);
}
 
开发者ID:psenger,项目名称:Jersey2-Security-JWT,代码行数:15,代码来源:TokenUtilTest.java

示例12: testGetVersionBad

import io.jsonwebtoken.impl.crypto.MacProvider; //导入方法依赖的package包/类
@Test
public void testGetVersionBad() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    calendar.add(Calendar.MINUTE, 15);
    String username = "Bob";
    String[] roles = new String[]{"user"};
    int version = 3;
    Date expires = calendar.getTime();
    Key key = MacProvider.generateKey();
    String jwtString = TokenUtil.getJWTString(username, roles, version, expires, key);
    int version1 = TokenUtil.getVersion(jwtString, MacProvider.generateKey());
    assertEquals(-1, version1);
}
 
开发者ID:psenger,项目名称:Jersey2-Security-JWT,代码行数:15,代码来源:TokenUtilTest.java

示例13: testGetRolesGood

import io.jsonwebtoken.impl.crypto.MacProvider; //导入方法依赖的package包/类
@Test
public void testGetRolesGood() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    calendar.add(Calendar.MINUTE, 15);
    String username = "Bob";
    String[] roles = new String[]{"user"};
    int version = 3;
    Date expires = calendar.getTime();
    Key key = MacProvider.generateKey();
    String jwtString = TokenUtil.getJWTString(username, roles, version, expires, key);
    String[] roles1 = TokenUtil.getRoles(jwtString, key);
    assertEquals(Arrays.toString(roles), Arrays.toString(roles1));
}
 
开发者ID:psenger,项目名称:Jersey2-Security-JWT,代码行数:15,代码来源:TokenUtilTest.java

示例14: testGetRolesBad

import io.jsonwebtoken.impl.crypto.MacProvider; //导入方法依赖的package包/类
@Test
public void testGetRolesBad() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    calendar.add(Calendar.MINUTE, 15);
    String username = "Bob";
    String[] roles = new String[]{"user"};
    int version = 3;
    Date expires = calendar.getTime();
    Key key = MacProvider.generateKey();
    String jwtString = TokenUtil.getJWTString(username, roles, version, expires, key);
    String[] roles1 = TokenUtil.getRoles(jwtString, MacProvider.generateKey());
    assertEquals(Arrays.toString(new String[]{}), Arrays.toString(roles1));
}
 
开发者ID:psenger,项目名称:Jersey2-Security-JWT,代码行数:15,代码来源:TokenUtilTest.java

示例15: testGetNamesGood

import io.jsonwebtoken.impl.crypto.MacProvider; //导入方法依赖的package包/类
@Test
public void testGetNamesGood() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    calendar.add(Calendar.MINUTE, 15);
    String username = "Bob";
    String[] roles = new String[]{"user"};
    int version = 3;
    Date expires = calendar.getTime();
    Key key = MacProvider.generateKey();
    String jwtString = TokenUtil.getJWTString(username, roles, version, expires, key);
    String username1 = TokenUtil.getName(jwtString, key);
    assertEquals(username, username1);
}
 
开发者ID:psenger,项目名称:Jersey2-Security-JWT,代码行数:15,代码来源:TokenUtilTest.java


注:本文中的io.jsonwebtoken.impl.crypto.MacProvider.generateKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。