|
1 | 1 | /*
|
2 |
| - * Copyright 2006-2018 the original author or authors. |
| 2 | + * Copyright 2006-2021 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
16 | 16 | package org.springframework.batch.core;
|
17 | 17 |
|
18 | 18 | import java.io.UnsupportedEncodingException;
|
19 |
| -import java.math.BigInteger; |
20 |
| -import java.security.MessageDigest; |
21 |
| -import java.security.NoSuchAlgorithmException; |
22 | 19 | import java.util.ArrayList;
|
23 | 20 | import java.util.Collections;
|
24 | 21 | import java.util.List;
|
25 | 22 | import java.util.Map;
|
26 | 23 |
|
27 | 24 | import org.springframework.util.Assert;
|
| 25 | +import org.springframework.util.DigestUtils; |
28 | 26 |
|
29 | 27 | /**
|
30 | 28 | * Default implementation of the {@link JobKeyGenerator} interface.
|
@@ -57,19 +55,8 @@ public String generateKey(JobParameters source) {
|
57 | 55 | stringBuffer.append(key).append("=").append(value).append(";");
|
58 | 56 | }
|
59 | 57 | }
|
60 |
| - |
61 |
| - MessageDigest digest; |
62 |
| - try { |
63 |
| - digest = MessageDigest.getInstance("MD5"); |
64 |
| - } catch (NoSuchAlgorithmException e) { |
65 |
| - throw new IllegalStateException( |
66 |
| - "MD5 algorithm not available. Fatal (should be in the JDK)."); |
67 |
| - } |
68 |
| - |
69 | 58 | try {
|
70 |
| - byte[] bytes = digest.digest(stringBuffer.toString().getBytes( |
71 |
| - "UTF-8")); |
72 |
| - return String.format("%032x", new BigInteger(1, bytes)); |
| 59 | + return DigestUtils.md5DigestAsHex(stringBuffer.toString().getBytes("UTF-8")); |
73 | 60 | } catch (UnsupportedEncodingException e) {
|
74 | 61 | throw new IllegalStateException(
|
75 | 62 | "UTF-8 encoding not available. Fatal (should be in the JDK).");
|
|
0 commit comments