|
28 | 28 | import java.io.ByteArrayOutputStream; |
29 | 29 | import java.io.IOException; |
30 | 30 | import java.io.InputStream; |
31 | | -import java.nio.ByteBuffer; |
| 31 | +import java.math.BigInteger; |
| 32 | +import java.nio.charset.StandardCharsets; |
32 | 33 | import java.security.MessageDigest; |
33 | 34 | import java.security.NoSuchAlgorithmException; |
34 | 35 | import java.util.List; |
@@ -102,11 +103,11 @@ void testGetTitle() throws XmpParsingException, BadFieldValueException |
102 | 103 | } |
103 | 104 |
|
104 | 105 | @Test |
105 | | - void testAltBagSeq() throws XmpParsingException, TransformerException, NoSuchAlgorithmException |
| 106 | + void testAltBagSeq() throws XmpParsingException, TransformerException, NoSuchAlgorithmException, IOException |
106 | 107 | { |
107 | 108 | InputStream fis = DomXmpParser.class.getResourceAsStream("/org/apache/xmpbox/parser/AltBagSeqTest.xml"); |
108 | 109 | XMPMetadata metadata=xdb.parse(fis); |
109 | | - checkTransform(metadata, "AA3B148E4F802DE4"); |
| 110 | + checkTransform(metadata, "96393121650279079517435472505216876362174786845882116375023427217573081361024"); |
110 | 111 | } |
111 | 112 |
|
112 | 113 | @Test |
@@ -327,12 +328,14 @@ void testSpaceTextValues() throws XmpParsingException |
327 | 328 | } |
328 | 329 |
|
329 | 330 | private void checkTransform(XMPMetadata metadata, String expected) |
330 | | - throws TransformerException, NoSuchAlgorithmException |
| 331 | + throws TransformerException, NoSuchAlgorithmException, IOException |
331 | 332 | { |
332 | 333 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
333 | 334 | serializer.serialize(metadata, baos, true); |
334 | | - byte[] digest = MessageDigest.getInstance("SHA-256").digest(baos.toByteArray()); |
335 | | - String result = String.format("%X", ByteBuffer.wrap(digest).getLong()); |
| 335 | + String replaced = baos.toString(StandardCharsets.UTF_8).replace("\r\n", "\n"); |
| 336 | + byte[] ba = replaced.getBytes(StandardCharsets.UTF_8); |
| 337 | + byte[] digest = MessageDigest.getInstance("SHA-256").digest(ba); |
| 338 | + String result = new BigInteger(1, digest).toString(); |
336 | 339 | assertEquals(expected, result); |
337 | 340 | } |
338 | 341 | } |
0 commit comments