| 5 | import java.security.NoSuchAlgorithmException; |
| 6 | |
| 7 | public class Crypto { |
| 8 | private final Faker faker; |
| 9 | |
| 10 | protected Crypto(Faker faker) { |
| 11 | this.faker = faker; |
| 12 | } |
| 13 | |
| 14 | public String md5() { |
| 15 | return generateString("MD5"); |
| 16 | } |
| 17 | |
| 18 | public String sha1() { |
| 19 | return generateString("SHA-1"); |
| 20 | } |
| 21 | |
| 22 | public String sha256() { |
| 23 | return generateString("SHA-256"); |
| 24 | } |
| 25 | |
| 26 | public String sha512() { |
| 27 | return generateString("SHA-512"); |
| 28 | } |
| 29 | |
| 30 | private String generateString(String algorithm) { |
| 31 | try { |
| 32 | MessageDigest messageDigest = MessageDigest.getInstance(algorithm); |
| 33 | String characters = faker.lorem().characters(); |
| 34 | messageDigest.update(characters.getBytes(), 0, characters.length()); |
| 35 | return new BigInteger(1, messageDigest.digest()).toString(16); |
| 36 | } catch (NoSuchAlgorithmException noSuchAlgorithmException) { |
| 37 | throw new RuntimeException(noSuchAlgorithmException); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | } |
nothing calls this directly
no outgoing calls
no test coverage detected