Commit 409fa565d4d302e76540ac3d925c04577e0c2083
1 parent
d16ba430
Exists in
master
Remove dependência de biblioteca da ANS.
Showing
2 changed files
with
37 additions
and
29 deletions
Show diff stats
pom.xml
| ... | ... | @@ -3,7 +3,7 @@ |
| 3 | 3 | <modelVersion>4.0.0</modelVersion> |
| 4 | 4 | <groupId>br.gov.ans.commons</groupId> |
| 5 | 5 | <artifactId>ans-commons-sei</artifactId> |
| 6 | - <version>1.2.0</version> | |
| 6 | + <version>1.2.1</version> | |
| 7 | 7 | <name>ans-commons-sei</name> |
| 8 | 8 | <packaging>jar</packaging> |
| 9 | 9 | <description>Biblioteca de apoio aos clientes do SEI-Broker.</description> |
| ... | ... | @@ -24,13 +24,6 @@ |
| 24 | 24 | <scope>provided</scope> |
| 25 | 25 | </dependency> |
| 26 | 26 | |
| 27 | - <!-- HASH --> | |
| 28 | - <dependency> | |
| 29 | - <groupId>br.gov.ans.commons</groupId> | |
| 30 | - <artifactId>ans-commons-security</artifactId> | |
| 31 | - <version>2.0</version> | |
| 32 | - </dependency> | |
| 33 | - | |
| 34 | 27 | <!-- BASE64 --> |
| 35 | 28 | <dependency> |
| 36 | 29 | <groupId>commons-codec</groupId> | ... | ... |
src/main/java/br/gov/ans/sei/utils/SeiHelper.java
| ... | ... | @@ -2,59 +2,74 @@ package br.gov.ans.sei.utils; |
| 2 | 2 | |
| 3 | 3 | import java.io.File; |
| 4 | 4 | import java.io.FileInputStream; |
| 5 | +import java.security.MessageDigest; | |
| 5 | 6 | import java.security.NoSuchAlgorithmException; |
| 6 | 7 | |
| 7 | 8 | import org.apache.commons.codec.binary.Base64; |
| 8 | 9 | |
| 9 | -import br.gov.ans.commons.security.crypt.HashUtils; | |
| 10 | - | |
| 11 | 10 | public class SeiHelper { |
| 12 | 11 | |
| 13 | 12 | /** |
| 14 | 13 | * Calcula o hash utilizando o algoritimo SHA-256. |
| 15 | - * | |
| 16 | - * @param conteudo entrada da qual será gerado o hash. | |
| 14 | + * | |
| 15 | + * @param conteudo | |
| 16 | + * entrada da qual será gerado o hash. | |
| 17 | 17 | * |
| 18 | 18 | * @return resultado do calculo do hash. |
| 19 | - * | |
| 19 | + * | |
| 20 | 20 | * @throws NoSuchAlgorithmException |
| 21 | 21 | * |
| 22 | 22 | */ |
| 23 | - public static String calcularHash(String conteudo) throws NoSuchAlgorithmException{ | |
| 24 | - return HashUtils.toSHA256(conteudo, null); | |
| 23 | + public static String calcularHash(String conteudo) throws NoSuchAlgorithmException { | |
| 24 | + MessageDigest sha256 = MessageDigest.getInstance("SHA-256"); | |
| 25 | + | |
| 26 | + byte[] inputBytes = conteudo.getBytes(); | |
| 27 | + byte[] inputHash = sha256.digest(inputBytes); | |
| 28 | + StringBuilder sb = new StringBuilder(); | |
| 29 | + | |
| 30 | + for (int i = 0; i < inputHash.length; i++) { | |
| 31 | + sb.append(Integer.toString((inputHash[i] & 0xff) + 0x100, 16).substring(1)); | |
| 32 | + } | |
| 33 | + | |
| 34 | + String generatedHash = sb.toString(); | |
| 35 | + | |
| 36 | + return generatedHash; | |
| 25 | 37 | } |
| 26 | - | |
| 38 | + | |
| 27 | 39 | /** |
| 28 | 40 | * Codifica entrada para Base64. |
| 29 | - * | |
| 30 | - * @param bytes Array de bytes que será codificado. | |
| 41 | + * | |
| 42 | + * @param bytes | |
| 43 | + * Array de bytes que será codificado. | |
| 31 | 44 | * |
| 32 | 45 | * @return resultado da conversão dos bytes. |
| 33 | - * | |
| 46 | + * | |
| 34 | 47 | * @throws NoSuchAlgorithmException |
| 35 | 48 | * |
| 36 | 49 | */ |
| 37 | - public static String getBase64(byte[] bytes){ | |
| 50 | + public static String getBase64(byte[] bytes) { | |
| 38 | 51 | return Base64.encodeBase64String(bytes); |
| 39 | 52 | } |
| 40 | - | |
| 53 | + | |
| 41 | 54 | /** |
| 42 | 55 | * Codifica entrada para Base64. |
| 43 | - * | |
| 44 | - * @param arquivo File que será codificado. | |
| 56 | + * | |
| 57 | + * @param arquivo | |
| 58 | + * File que será codificado. | |
| 45 | 59 | * |
| 46 | 60 | * @return resultado da conversão dos bytes do arquivo. |
| 47 | - * | |
| 61 | + * | |
| 48 | 62 | * @throws NoSuchAlgorithmException |
| 49 | 63 | * |
| 50 | 64 | */ |
| 51 | - public static String getBase64(File arquivo) throws Exception{ | |
| 52 | - byte[] bytes = new byte[(int) arquivo.length()]; | |
| 53 | - | |
| 54 | - FileInputStream fileInputStream = new FileInputStream(arquivo); | |
| 65 | + public static String getBase64(File arquivo) throws Exception { | |
| 66 | + byte[] bytes = new byte[(int) arquivo.length()]; | |
| 67 | + | |
| 68 | + FileInputStream fileInputStream = new FileInputStream(arquivo); | |
| 55 | 69 | fileInputStream.read(bytes); |
| 56 | 70 | fileInputStream.close(); |
| 57 | - | |
| 71 | + | |
| 58 | 72 | return getBase64(bytes); |
| 59 | 73 | } |
| 74 | + | |
| 60 | 75 | } | ... | ... |