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


Java RandomStringUtils.random方法代码示例

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


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

示例1: createMockStoreFile

import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
protected StoreFile createMockStoreFile(final long sizeInBytes, final long seqId) {
  StoreFile mockSf = mock(StoreFile.class);
  StoreFile.Reader reader = mock(StoreFile.Reader.class);
  String stringPath = "/hbase/testTable/regionA/"
      + RandomStringUtils.random(FILENAME_LENGTH, 0, 0, true, true, null, random);
  Path path = new Path(stringPath);


  when(reader.getSequenceID()).thenReturn(seqId);
  when(reader.getTotalUncompressedBytes()).thenReturn(sizeInBytes);
  when(reader.length()).thenReturn(sizeInBytes);

  when(mockSf.getPath()).thenReturn(path);
  when(mockSf.excludeFromMinorCompaction()).thenReturn(false);
  when(mockSf.isReference()).thenReturn(false); // TODO come back to
  // this when selection takes this into account
  when(mockSf.getReader()).thenReturn(reader);
  String toString = Objects.toStringHelper("MockStoreFile")
      .add("isReference", false)
      .add("fileSize", StringUtils.humanReadableInt(sizeInBytes))
      .add("seqId", seqId)
      .add("path", stringPath).toString();
  when(mockSf.toString()).thenReturn(toString);

  return mockSf;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:27,代码来源:MockStoreFileGenerator.java

示例2: getEncodingAESKey

import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
/**
 * 生成微信EncodingAESKey
 * @return
 */
public static String getEncodingAESKey() {
	String ret = Constants.EMPTY;		
	try {
		// Initialize SecureRandom
		// This is a lengthy operation, to be done only upon
		// initialization of the application
		SecureRandom prng = SecureRandom.getInstance("SHA1PRNG");

		// generate a random number
		String randomNum = new Integer(prng.nextInt()).toString();

		// get its digest
		MessageDigest sha = MessageDigest.getInstance("SHA-1");
		byte[] result = sha.digest(randomNum.getBytes());

		ret = hexEncode(result);
		
		ret += RandomStringUtils.random(3, chars);
	} catch (NoSuchAlgorithmException ex) {
		System.err.println(ex);
	}
	return ret;
}
 
开发者ID:simbest,项目名称:simbest-cores,代码行数:28,代码来源:AppCodeGenerator.java

示例3: RandomTextDataGenerator

import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
/**
 * Constructor for {@link RandomTextDataGenerator}.
 * @param size the total number of words to consider.
 * @param seed Random number generator seed for repeatability
 * @param wordSize Size of each word
 */
RandomTextDataGenerator(int size, Long seed, int wordSize) {
  random = new Random(seed);
  words = new String[size];
  
  //TODO change the default with the actual stats
  //TODO do u need varied sized words?
  for (int i = 0; i < size; ++i) {
    words[i] = 
      RandomStringUtils.random(wordSize, 0, 0, true, false, null, random);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:18,代码来源:RandomTextDataGenerator.java

示例4: deleteUser

import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
@RequestMapping(value="deleteuser.jy", method = {RequestMethod.GET, RequestMethod.POST})
public String deleteUser(JYUser user, Model model) {
	logger.info("Welcome LoginController deleteUser!" + new Date());
	String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789~`[email protected]#$%^&*()-_=+[{]}\\|;:\'\",<.>/?";
	String pwd = RandomStringUtils.random( 15, characters );
	user.setUpwd(pwd);
	jYUserService.deleteUser(user);
	return "redirect:/userlist.jy";
}
 
开发者ID:okfarm09,项目名称:JYLAND,代码行数:10,代码来源:LoginController.java

示例5: jwsMAC

import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
/**
     * JWS
     * 使用HMAC SHA-256 进行加密 与 解密
     * 基于相同的 secret (对称算法)
     * <p/>
     * 算法     Secret长度
     * HS256   32
     * HS384   64
     * HS512   64
     *
     * @throws Exception
     */
    @Test
    public void jwsMAC() throws Exception {

        String sharedSecret = RandomStringUtils.random(64, true, true);
        JWSSigner jwsSigner = new MACSigner(sharedSecret);

        //加密
//        JWSHeader header = new JWSHeader(JWSAlgorithm.HS256);
//        JWSHeader header = new JWSHeader(JWSAlgorithm.HS384);
        JWSHeader header = new JWSHeader(JWSAlgorithm.HS512);
        final String payloadText = "I am MyOIDC";
        Payload payload = new Payload(payloadText);
        JWSObject jwsObject = new JWSObject(header, payload);

        jwsObject.sign(jwsSigner);
        //获取 idToken
        final String idToken = jwsObject.serialize();
        System.out.println(payloadText + " -> id_token: " + idToken);

        //解密
        JWSVerifier verifier = new MACVerifier(sharedSecret);
        final JWSObject parseJWS = JWSObject.parse(idToken);
        final boolean verify = parseJWS.verify(verifier);

        assertTrue(verify);
        final String decryptPayload = parseJWS.getPayload().toString();
        assertEquals(decryptPayload, payloadText);
    }
 
开发者ID:monkeyk,项目名称:MyOIDC,代码行数:41,代码来源:NimbusJoseJwtTest.java

示例6: jwtMAC

import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
/**
     * JWT
     * 使用HMAC SHA-256 进行加密 与 解密
     * 基于相同的 secret (对称算法)
     * <p/>
     * 算法     Secret长度
     * HS256   32
     * HS384   64
     * HS512   64
     *
     * @throws Exception
     */
    @Test
    public void jwtMAC() throws Exception {

        String sharedSecret = RandomStringUtils.random(64, true, true);
        JWSSigner jwsSigner = new MACSigner(sharedSecret);

        //生成idToken
        final String payloadText = "I am MyOIDC";
        JWTClaimsSet claimsSet = new JWTClaimsSet.Builder()
                .subject("subject")
                .issuer("https://andaily.com")
                .claim("payloadText", payloadText)
                .expirationTime(new Date(new Date().getTime() + 60 * 1000))
                .build();

//        final JWSHeader header = new JWSHeader(JWSAlgorithm.HS256);
//        final JWSHeader header = new JWSHeader(JWSAlgorithm.HS384);
        final JWSHeader header = new JWSHeader(JWSAlgorithm.HS512);
        SignedJWT signedJWT = new SignedJWT(header, claimsSet);
        signedJWT.sign(jwsSigner);

        final String idToken = signedJWT.serialize();

        //校验idToken
        final SignedJWT parseJWT = SignedJWT.parse(idToken);
        JWSVerifier jwsVerifier = new MACVerifier(sharedSecret);
        final boolean verify = parseJWT.verify(jwsVerifier);

        assertTrue(verify);
//        final Payload payload = parseJWT.getPayload();
        final JWTClaimsSet jwtClaimsSet = parseJWT.getJWTClaimsSet();
        assertEquals(jwtClaimsSet.getSubject(), "subject");

    }
 
开发者ID:monkeyk,项目名称:MyOIDC,代码行数:47,代码来源:NimbusJoseJwtTest.java

示例7: cryptBytes

import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
public static String cryptBytes(String hashType, String salt, byte[] bytes) {
    if (hashType == null) {
        hashType = "SHA";
    }
    if (salt == null) {
        salt = RandomStringUtils.random(new SecureRandom().nextInt(15) + 1, CRYPT_CHAR_SET);
    }
    StringBuilder sb = new StringBuilder();
    sb.append("$").append(hashType).append("$").append(salt).append("$");
    sb.append(getCryptedBytes(hashType, salt, bytes));
    return sb.toString();
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:13,代码来源:HashCrypt.java

示例8: UserInfoBuilder

import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
public UserInfoBuilder(final String username,
                       final Long userId,
                       final SystemUser.Role role) {
    this.username = username;
    this.userId = userId;
    this.role = role;
    this.password = RandomStringUtils.random(32);
    this.privileges = Collections.emptySet();
    this.coordinator = false;
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:11,代码来源:UserInfo.java

示例9: createToken

import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
/**
 * 创建CXRF Token,避免表单重复提交或者跨站操作
 * @param response 生成token,path为当前页面的路径,比如:/teacher
 * @return
 */
public String createToken(HttpServletRequest request,HttpServletResponse response) {
    String token = RandomStringUtils.random(32,true,true);

    Cookie cookie = new Cookie(TOKEN_KEY,DESUtils.encrypt(token,Constants.HTTP_ENCRYPT_KEY));
    cookie.setDomain(systemConfig.getCookieDomain());
    cookie.setPath(this.getRequestPath(request));
    //cookie.setMaxAge(TOKEN_MAX_AGE);
    response.addCookie(cookie);
    return token;
}
 
开发者ID:javahongxi,项目名称:whatsmars,代码行数:16,代码来源:BaseController.java

示例10: createResource

import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
@Override
protected void createResource() {
    String name = StringUtils.isNotEmpty(fileName) ? fileName : RandomStringUtils.random(16, true, true);

    resource = new com.vaadin.server.StreamResource(() ->
            streamSupplier.get(), name);

    com.vaadin.server.StreamResource vStreamResource = (com.vaadin.server.StreamResource) this.resource;

    vStreamResource.setCacheTime(cacheTime);
    vStreamResource.setBufferSize(bufferSize);
    vStreamResource.setMIMEType(mimeType);
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:14,代码来源:WebStreamResource.java

示例11: generateTicket

import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
private String generateTicket() {
    String ticket = null;
    while (ticket == null || ticketDao.exists(ticket)) {
        ticket = RandomStringUtils.random(TICKET_SIZE, POSSIBLE_TICKET_CHARS);
    }
    return ticket;
}
 
开发者ID:mateli,项目名称:OpenCyclos,代码行数:8,代码来源:TicketServiceImpl.java

示例12: generate

import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
public static String generate() {
    return RandomStringUtils.random(32, true, true);
}
 
开发者ID:monkeyk,项目名称:oauth2-shiro,代码行数:4,代码来源:GuidGenerator.java

示例13: generateClientId

import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
public static String generateClientId() {
    return RandomStringUtils.random(20, true, true);
}
 
开发者ID:monkeyk,项目名称:oauth2-shiro,代码行数:4,代码来源:GuidGenerator.java

示例14: generateClientSecret

import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
public static String generateClientSecret() {
    return RandomStringUtils.random(20, true, true);
}
 
开发者ID:monkeyk,项目名称:oauth2-shiro,代码行数:4,代码来源:GuidGenerator.java

示例15: paintComponent

import org.apache.commons.lang.RandomStringUtils; //导入方法依赖的package包/类
@Override
protected void paintComponent(Graphics g) {
    String key = RandomStringUtils.random(5);
    new CoverArtController.AutoCover((Graphics2D) g, key, "Artist with a very long name", "Album", width, height).paintCover();
}
 
开发者ID:airsonic,项目名称:airsonic,代码行数:6,代码来源:AutoCoverDemo.java


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