當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。