MCPcopy Create free account
hub / github.com/0linlin0/CyberBox / generateRandomIV

Method generateRandomIV

Skay_Exp/src/tools/CryptLib.java:264–281  ·  view source on GitHub ↗

this function generates random string for given length @param length Desired length @return

(int length)

Source from the content-addressed store, hash-verified

262 * * @return
263 */
264 public static String generateRandomIV(int length)
265 {
266 SecureRandom ranGen = new SecureRandom();
267 byte[] aesKey = new byte[16];
268 ranGen.nextBytes(aesKey);
269 StringBuffer result = new StringBuffer();
270 for (byte b : aesKey) {
271 result.append(String.format("%02x", b)); //convert to hex
272 }
273 if(length> result.toString().length())
274 {
275 return result.toString();
276 }
277 else
278 {
279 return result.toString().substring(0, length);
280 }
281 }
282}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected