public static String generateCookie() { byte[] cookie = new byte[32]; secureRandom.nextBytes(cookie); return Util.toHexString(cookie); }
@Nonnull public static String toHexString(@Nonnull byte[] bytes) { return toHexString(bytes,0,bytes.length); }
/** * Determines the file name from md5sum. */ private static @Nonnull File getFingerprintFile(@Nonnull byte[] md5sum) { assert md5sum.length==16; return new File( Jenkins.getInstance().getRootDir(), "fingerprints/"+ Util.toHexString(md5sum,0,1)+'/'+Util.toHexString(md5sum,1,1)+'/'+Util.toHexString(md5sum,2,md5sum.length-2)+".xml"); }
/** * Gets the MD5 hash string. */ @Exported(name="hash") public @Nonnull String getHashString() { return Util.toHexString(md5sum); }
@SuppressFBWarnings("NP_NONNULL_RETURN_VIOLATION") private @Nonnull String plainSecretToHashInHex(@Nonnull String secretValueInPlainText) { byte[] hashBytes = plainSecretToHashBytes(secretValueInPlainText); return Util.toHexString(hashBytes); }
@Deprecated private void _changeApiToken(){ byte[] random = new byte[16]; // 16x8=128bit worth of randomness, since we use md5 digest as the API token RANDOM.nextBytes(random); apiToken = Secret.fromString(Util.toHexString(random)); }
/** * Computes the message authentication code and return it as a string. * While redundant, often convenient. */ public String mac(String message) { try { return Util.toHexString(mac(message.getBytes("UTF-8"))); } catch (UnsupportedEncodingException e) { throw new AssertionError(e); } }
/** * @param build * set to non-null if {@link Fingerprint} to be created (if so) * will have this build as the owner. Otherwise null, to indicate * an owner-less build. * @throws IOException Loading error */ public @Nonnull Fingerprint getOrCreate(@CheckForNull AbstractBuild build, @Nonnull String fileName, @Nonnull byte[] md5sum) throws IOException { return getOrCreate(build,fileName, Util.toHexString(md5sum)); }
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { byte[] data = (byte[]) source; writer.setValue(Util.toHexString(data)); }
return toHexString(md5.digest()); } catch (NoSuchAlgorithmException e) { throw new IOException("MD5 not installed",e); // impossible
public InputStream extract(InputStream _in) throws IOException { HeadBufferingStream in = new HeadBufferingStream(_in,SIDE_BUFFER_SIZE); try { return new GZIPInputStream(in, 8192, true); } catch (IOException e) { // various people reported "java.io.IOException: Not in GZIP format" here, so diagnose this problem better in.fillSide(); throw new IOException(e.getMessage()+"\nstream="+Util.toHexString(in.getSideBuffer()),e); } } public OutputStream compress(OutputStream out) throws IOException {
/** * {@inheritDoc} */ @Override protected synchronized String issueCrumb(ServletRequest request, String salt) { if (request instanceof HttpServletRequest) { if (md != null) { HttpServletRequest req = (HttpServletRequest) request; StringBuilder buffer = new StringBuilder(); Authentication a = Jenkins.getAuthentication(); if (a != null) { buffer.append(a.getName()); } buffer.append(';'); if (!isExcludeClientIPFromCrumb()) { buffer.append(getClientIP(req)); } md.update(buffer.toString().getBytes()); return Util.toHexString(md.digest(salt.getBytes())); } } return null; }
/** * Create a new token with the given name and return it id and secret value. * Result meant to be sent / displayed and then discarded. */ public synchronized @Nonnull TokenUuidAndPlainValue generateNewToken(@Nonnull String name) { // 16x8=128bit worth of randomness, using brute-force you need on average 2^127 tries (~10^37) byte[] random = new byte[16]; RANDOM.nextBytes(random); String secretValue = Util.toHexString(random); String tokenTheUserWillUse = HASH_VERSION + secretValue; assert tokenTheUserWillUse.length() == 2 + 32; String secretValueHashed = this.plainSecretToHashInHex(secretValue); HashValue hashValue = new HashValue(HASH_VERSION, secretValueHashed); HashedToken token = HashedToken.buildNew(name, hashValue); this.addToken(token); return new TokenUuidAndPlainValue(token.uuid, tokenTheUserWillUse); }
public void doGenerateSecretToken(@AncestorInPath final Job<?, ?> project, StaplerResponse response) { byte[] random = new byte[16]; // 16x8=128bit worth of randomness, since we use md5 digest as the API token RANDOM.nextBytes(random); String secretToken = Util.toHexString(random); response.setHeader("script", "document.getElementById('secretToken').value='" + secretToken + "'"); }
w.print(Util.toHexString(md5sum)); w.println("</md5sum>"); w.print(" <fileName>");
public DefaultConfidentialStore(File rootDir) throws IOException, InterruptedException { this.rootDir = rootDir; if (rootDir.mkdirs()) { // protect this directory. but don't change the permission of the existing directory // in case the administrator changed this. new FilePath(rootDir).chmod(0700); } TextFile masterSecret = new TextFile(new File(rootDir,"master.key")); if (!masterSecret.exists()) { // we are only going to use small number of bits (since export control limits AES key length) // but let's generate a long enough key anyway masterSecret.write(Util.toHexString(randomBytes(128))); } this.masterKey = Util.toAes128Key(masterSecret.readTrim()); }
/** * Returns the persisted hex string value. * * If the value isn't persisted, a new random value is created. * * @throws Error * If the secret fails to load. Not throwing a checked exception is for the convenience * of the caller. */ public String get() { try { if (secret==null) { synchronized (this) { if (secret==null) { byte[] payload = load(); if (payload==null) { payload = ConfidentialStore.get().randomBytes(length/2); store(payload); } secret = Util.toHexString(payload).substring(0,length); } } } return secret; } catch (IOException e) { throw new Error("Failed to load the key: "+getId(),e); } } }
byte[] random = new byte[32]; sr.nextBytes(random); secretKey = Util.toHexString(random); secretFile.write(secretKey);
/** * Determines the file name from md5sum. */ private static File getFingerprintFile(byte[] md5sum) { assert md5sum.length==16; return new File( Hudson.getInstance().getRootDir(), "fingerprints/"+ Util.toHexString(md5sum,0,1)+'/'+Util.toHexString(md5sum,1,1)+'/'+Util.toHexString(md5sum,2,md5sum.length-2)+".xml"); }
/** * Determines the file name from md5sum. */ private static @Nonnull File getFingerprintFile(@Nonnull byte[] md5sum) { assert md5sum.length==16; return new File( Jenkins.getInstance().getRootDir(), "fingerprints/"+ Util.toHexString(md5sum,0,1)+'/'+Util.toHexString(md5sum,1,1)+'/'+Util.toHexString(md5sum,2,md5sum.length-2)+".xml"); }