Пример #1
0
 /**
  * 生成文件摘要
  *
  * @param strFilePath 文件路径
  * @param file_digest_type 摘要算法
  * @return 文件摘要结果
  */
 public static String getAbstract(String strFilePath, String file_digest_type) throws IOException {
   PartSource file = new FilePartSource(new File(strFilePath));
   if (file_digest_type.equals("MD5")) {
     return DigestUtils.md5Hex(file.createInputStream());
   } else if (file_digest_type.equals("SHA")) {
     return DigestUtils.sha256Hex(file.createInputStream());
   } else {
     return "";
   }
 }
Пример #2
0
 private Path getFilePath(String url, Path hostPath) throws UnsupportedEncodingException {
   Path filePath;
   if (hashFilename) {
     String filenameEncoded = DigestUtils.sha256Hex(url);
     filePath = hostPath.resolve(filenameEncoded);
   } else {
     filePath = hostPath.resolve(URLEncoder.encode(url, "UTF-8"));
   }
   return filePath;
 }
Пример #3
0
 /**
  * 生成文件摘要
  *
  * @param strFilePath 文件路径
  * @param file_digest_type 摘要算法
  * @return 文件摘要结果
  */
 public static String getAbstract(String strFilePath, String file_digest_type) throws IOException {
   PartSource file = new FilePartSource(new File(strFilePath));
   switch (file_digest_type) {
     case "MD5":
       return DigestUtils.md5Hex(file.createInputStream());
     case "SHA":
       return DigestUtils.sha256Hex(file.createInputStream());
     default:
       return "";
   }
 }
Пример #4
0
  /** ${@inheritDoc} */
  @Override
  public User createUser(
      String firstName,
      String lastName,
      String emailAddress,
      String phoneNumber,
      String username,
      String password,
      String imageUrl,
      boolean isAdmin,
      boolean isCoordinator,
      boolean isHeadMentorMom,
      boolean isMentorMom,
      boolean isHeadTableLead,
      boolean isTableLead,
      boolean isOutreachLead)
      throws UserException {
    // Make sure the user doesn't already exist
    if (!ObjectUtils.equals(null, userRepository.findByFirstNameAndLastName(firstName, lastName))) {
      throw new UserException("The user [" + firstName + " " + lastName + "] already exists");
    }

    // If a password has been provided, hash it
    if (!StringUtils.isEmpty(password)) {
      password = DigestUtils.sha256Hex(password);
    }

    // Create the new user object
    User user =
        new User(
            firstName,
            lastName,
            emailAddress,
            phoneNumber,
            username,
            password,
            imageUrl,
            isAdmin,
            isCoordinator,
            isHeadMentorMom,
            isMentorMom,
            isHeadTableLead,
            isTableLead,
            isOutreachLead);

    // Save the user to the database
    user = userRepository.save(user);

    // Return the user
    return user;
  }
Пример #5
0
 public static String sha2(final String str)
     throws UnsupportedEncodingException, NoSuchAlgorithmException {
   log.info(String.format("Calculate sha2 hash for %d bytes", str.length()));
   return DigestUtils.sha256Hex(str);
 }
Пример #6
0
 public static String toHashPassword(String plainPassword) {
   String hashedPassword = DigestUtils.sha256Hex(plainPassword);
   return hashedPassword;
 }