hudson.Util.getDigestOf()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(293)

本文整理了Java中hudson.Util.getDigestOf()方法的一些代码示例,展示了Util.getDigestOf()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.getDigestOf()方法的具体详情如下:
包路径:hudson.Util
类名称:Util
方法名:getDigestOf

Util.getDigestOf介绍

[英]Computes the MD5 digest of a file.
[中]计算文件的MD5摘要。

代码示例

代码示例来源:origin: jenkinsci/jenkins

  1. @Override
  2. public String invoke(File f, VirtualChannel channel) throws IOException {
  3. return Util.getDigestOf(reading(f));
  4. }
  5. }

代码示例来源:origin: jenkinsci/jenkins

  1. @Nonnull
  2. public static String getDigestOf(@Nonnull String text) {
  3. try {
  4. return getDigestOf(new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8)));
  5. } catch (IOException e) {
  6. throw new Error(e);
  7. }
  8. }

代码示例来源:origin: jenkinsci/jenkins

  1. /**
  2. * Computes the MD5 digest of a file.
  3. * @param file a file
  4. * @return a 32-character string
  5. * @throws IOException in case reading fails
  6. * @since 1.525
  7. */
  8. @Nonnull
  9. public static String getDigestOf(@Nonnull File file) throws IOException {
  10. // Note: getDigestOf() closes the input stream.
  11. return getDigestOf(Files.newInputStream(fileToPath(file)));
  12. }

代码示例来源:origin: jenkinsci/jenkins

  1. /**
  2. * Returns the unique identifier of this Jenkins that has been historically used to identify
  3. * this Jenkins to the outside world.
  4. *
  5. * <p>
  6. * This form of identifier is weak in that it can be impersonated by others. See
  7. * https://wiki.jenkins-ci.org/display/JENKINS/Instance+Identity for more modern form of instance ID
  8. * that can be challenged and verified.
  9. *
  10. * @since 1.498
  11. */
  12. @SuppressWarnings("deprecation")
  13. public String getLegacyInstanceId() {
  14. return Util.getDigestOf(getSecretKey());
  15. }

代码示例来源:origin: jenkinsci/jenkins

  1. context.setAttribute("version",ver);
  2. VERSION_HASH = Util.getDigestOf(ver).substring(0, 8);
  3. SESSION_HASH = Util.getDigestOf(ver+System.currentTimeMillis()).substring(0, 8);

代码示例来源:origin: jenkinsci/jenkins

  1. /**
  2. * If {@code jenkins.exe} is old compared to our copy,
  3. * schedule an overwrite (except that since it's currently running,
  4. * we can only do it when Jenkins restarts next time.)
  5. */
  6. private void updateJenkinsExeIfNeeded() {
  7. try {
  8. File baseDir = getBaseDir();
  9. URL exe = getClass().getResource("/windows-service/jenkins.exe");
  10. String ourCopy = Util.getDigestOf(exe.openStream());
  11. for (String name : new String[]{"hudson.exe","jenkins.exe"}) {
  12. try {
  13. File currentCopy = new File(baseDir,name);
  14. if(!currentCopy.exists()) continue;
  15. String curCopy = new FilePath(currentCopy).digest();
  16. if(ourCopy.equals(curCopy)) continue; // identical
  17. File stage = new File(baseDir,name+".new");
  18. FileUtils.copyURLToFile(exe,stage);
  19. Kernel32.INSTANCE.MoveFileExA(stage.getAbsolutePath(),currentCopy.getAbsolutePath(),MOVEFILE_DELAY_UNTIL_REBOOT|MOVEFILE_REPLACE_EXISTING);
  20. LOGGER.info("Scheduled a replacement of "+name);
  21. } catch (IOException e) {
  22. LOGGER.log(Level.SEVERE, "Failed to replace "+name,e);
  23. } catch (InterruptedException e) {
  24. }
  25. }
  26. } catch (IOException e) {
  27. LOGGER.log(Level.SEVERE, "Failed to replace jenkins.exe",e);
  28. }
  29. }

代码示例来源:origin: jenkinsci/jenkins

  1. private void addLegacyToken(@Nonnull Secret legacyToken, boolean migrationFromExistingLegacy) {
  2. String tokenUserUseNormally = Util.getDigestOf(legacyToken.getPlainText());
  3. String secretValueHashed = this.plainSecretToHashInHex(tokenUserUseNormally);
  4. HashValue hashValue = new HashValue(LEGACY_VERSION, secretValueHashed);
  5. HashedToken token = HashedToken.buildNewFromLegacy(hashValue, migrationFromExistingLegacy);
  6. this.addToken(token);
  7. }

代码示例来源:origin: jenkinsci/jenkins

  1. @Nonnull
  2. @Restricted(NoExternalUse.class)
  3. /*package*/ String getApiTokenInsecure() {
  4. if(apiToken == null){
  5. return Messages.ApiTokenProperty_NoLegacyToken();
  6. }
  7. String p = apiToken.getPlainText();
  8. if (p.equals(Util.getDigestOf(Jenkins.getInstance().getSecretKey()+":"+user.getId()))) {
  9. // if the current token is the initial value created by pre SECURITY-49 Jenkins, we can't use that.
  10. // force using the newer value
  11. apiToken = Secret.fromString(p=API_KEY_SEED.mac(user.getId()));
  12. }
  13. return Util.getDigestOf(p);
  14. }

代码示例来源:origin: jenkinsci/jenkins

  1. public static @CheckForNull User isConnectingUsingApiToken(String username, String tokenValue){
  2. User user = User.getById(username, false);
  3. if(user == null){
  4. ApiTokenPropertyConfiguration apiTokenConfiguration = GlobalConfiguration.all().getInstance(ApiTokenPropertyConfiguration.class);
  5. if(apiTokenConfiguration.isTokenGenerationOnCreationEnabled()){
  6. String generatedTokenOnCreation = Util.getDigestOf(ApiTokenProperty.API_KEY_SEED.mac(username));
  7. boolean areTokenEqual = MessageDigest.isEqual(
  8. generatedTokenOnCreation.getBytes(StandardCharsets.US_ASCII),
  9. tokenValue.getBytes(StandardCharsets.US_ASCII)
  10. );
  11. if(areTokenEqual){
  12. // directly return the user freshly created
  13. // and no need to check its token as the generated token
  14. // will be the same as the one we checked just above
  15. return User.getById(username, true);
  16. }
  17. }
  18. }else{
  19. ApiTokenProperty t = user.getProperty(ApiTokenProperty.class);
  20. if (t!=null && t.matchesPassword(tokenValue)) {
  21. return user;
  22. }
  23. }
  24. return null;
  25. }
  26. }

代码示例来源:origin: jenkinsci/jenkins

  1. InputStream fingerprintInput = baseFile.open();
  2. try {
  3. rsp.forward(Jenkins.getInstance().getFingerprint(Util.getDigestOf(fingerprintInput)), "/", req);
  4. } finally {
  5. fingerprintInput.close();

代码示例来源:origin: jenkinsci/jenkins

  1. /**
  2. * Do a finger-print check.
  3. */
  4. @RequirePOST
  5. public void doDoFingerprintCheck( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
  6. // Parse the request
  7. try (MultipartFormDataParser p = new MultipartFormDataParser(req)) {
  8. if (isUseCrumbs() && !getCrumbIssuer().validateCrumb(req, p)) {
  9. // TODO investigate whether this check can be removed
  10. rsp.sendError(HttpServletResponse.SC_FORBIDDEN, "No crumb found");
  11. }
  12. rsp.sendRedirect2(req.getContextPath()+"/fingerprint/"+
  13. Util.getDigestOf(p.getFileItem("name").getInputStream())+'/');
  14. }
  15. }

代码示例来源:origin: hudson/hudson-2.x

  1. public static String getDigestOf(String text) {
  2. try {
  3. return getDigestOf(new ByteArrayInputStream(text.getBytes("UTF-8")));
  4. } catch (IOException e) {
  5. throw new Error(e);
  6. }
  7. }

代码示例来源:origin: org.eclipse.hudson.main/hudson-core

  1. public static String getDigestOf(String text) {
  2. try {
  3. return getDigestOf(new ByteArrayInputStream(text.getBytes("UTF-8")));
  4. } catch (IOException e) {
  5. throw new Error(e);
  6. }
  7. }

代码示例来源:origin: org.jvnet.hudson.main/hudson-core

  1. /**
  2. * Gets the 8 character-wide hash code for this combination
  3. */
  4. public String digest() {
  5. return Util.getDigestOf(toString());
  6. }

代码示例来源:origin: org.jenkins-ci.plugins/matrix-project

  1. /**
  2. * Gets the 8 character-wide hash code for this combination
  3. */
  4. public String digest() {
  5. return Util.getDigestOf(toString());
  6. }

代码示例来源:origin: org.eclipse.hudson.main/hudson-core

  1. /**
  2. * Gets the 8 character-wide hash code for this combination
  3. */
  4. public String digest() {
  5. return Util.getDigestOf(toString());
  6. }

代码示例来源:origin: org.jvnet.hudson.main/hudson-test-harness

  1. @Override
  2. protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  3. String path = req.getServletPath();
  4. String d = Util.getDigestOf(path);
  5. File cache = new File(cacheFolder, d);
  6. if(!cache.exists()) {
  7. URL url = new URL("http://hudson-ci.org/" + path);
  8. FileUtils.copyURLToFile(url,cache);
  9. }
  10. resp.setContentType(getMimeType(path));
  11. IOUtils.copy(cache,resp.getOutputStream());
  12. }

代码示例来源:origin: jenkinsci/docker-plugin

  1. public static String getInstanceId() {
  2. try {
  3. if( _id == null ) {
  4. _id = Util.getDigestOf(
  5. new ByteArrayInputStream(InstanceIdentity.get().getPublic().getEncoded()));
  6. }
  7. } catch (IOException e) {
  8. LOG.error("Could not get Jenkins instance ID.");
  9. _id = "";
  10. }
  11. return _id;
  12. }

代码示例来源:origin: org.jenkins-ci.modules/systemd-slave-installer

  1. @Override
  2. public SlaveInstaller createIfApplicable(Channel c) throws IOException, InterruptedException {
  3. if (c.call(new HasSystemd())) {
  4. RSAPublicKey key = id.getPublic();
  5. String instanceId = Util.getDigestOf(new String(Base64.encodeBase64(key.getEncoded()))).substring(0,8);
  6. return new SystemdSlaveInstaller(instanceId);
  7. }
  8. return null;
  9. }

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

  1. @Nonnull
  2. @Restricted(NoExternalUse.class)
  3. /*package*/ String getApiTokenInsecure() {
  4. String p = apiToken.getPlainText();
  5. if (p.equals(Util.getDigestOf(Jenkins.getInstance().getSecretKey()+":"+user.getId()))) {
  6. // if the current token is the initial value created by pre SECURITY-49 Jenkins, we can't use that.
  7. // force using the newer value
  8. apiToken = Secret.fromString(p=API_KEY_SEED.mac(user.getId()));
  9. }
  10. return Util.getDigestOf(p);
  11. }

相关文章