Skip to content

Commit

Permalink
Fixed the parsing of the big integers in the PVK files
Browse files Browse the repository at this point in the history
  • Loading branch information
ebourg committed Feb 20, 2017
1 parent 9c36970 commit cca6c57
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions jsign-core/src/main/java/net/jsign/PVK.java
Expand Up @@ -175,8 +175,8 @@ private static PrivateKey parseKey(byte[] key) throws GeneralSecurityException {
* @param length the number of bytes read
*/
private static BigInteger getBigInteger(ByteBuffer buffer, int length) {
byte[] array = new byte[length];
buffer.get(array);
byte[] array = new byte[length + 1];
buffer.get(array, 0, length);

return new BigInteger(reverse(array));
}
Expand Down
7 changes: 7 additions & 0 deletions jsign-core/src/test/java/net/jsign/PVKTest.java
Expand Up @@ -31,6 +31,12 @@ public class PVKTest extends TestCase {
"38747175970780043259305835482179875435536692028556840275049932216177725039464021845390956" +
"48749365951054152409123155429217112278873");

private static final BigInteger MODULUS =
new BigInteger("10827562372927185168634933681922029928807680158373213016018185402418682816925449513077404" +
"86528413817409261870616567143593547418892051759497008851701669594509162542812252927073053" +
"63776062597224618555740476093967060229674515611975718626261740683864624806740655247266908" +
"985568698016685062096774422670704602453741");

public void testParseUnencrypted() throws Exception {
testParse("src/test/resources/privatekey.pvk");
}
Expand All @@ -49,6 +55,7 @@ private void testParse(String filename) throws Exception {

RSAPrivateKey rsakey = (RSAPrivateKey) key;
assertEquals("private exponent", PRIVATE_EXPONENT, rsakey.getPrivateExponent());
assertEquals("modulus", MODULUS, rsakey.getModulus());
}

public void testCompare() throws Exception {
Expand Down

0 comments on commit cca6c57

Please sign in to comment.