in jsign-core/src/main/java/net/jsign/PVK.java [65:96]
public static PrivateKey parse(ByteBuffer buffer, String password) throws GeneralSecurityException {
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.rewind();
long magic = buffer.getInt() & 0xFFFFFFFFL;
if (PVK_MAGIC != magic) {
throw new IllegalArgumentException("PVK header signature not found");
}
buffer.position(buffer.position() + 4); // reserved
int keyType = buffer.getInt();
boolean encrypted = buffer.getInt() != 0;
int saltLength = buffer.getInt();
int keyLength = buffer.getInt();
byte[] salt = new byte[saltLength];
buffer.get(salt);
// BLOBHEADER structure: https://msdn.microsoft.com/en-us/library/cc235198.aspx
byte btype = buffer.get();
byte version = buffer.get();
buffer.position(buffer.position() + 2); // reserved
int keyalg = buffer.getInt();
byte[] key = new byte[keyLength - 8];
buffer.get(key);
if (encrypted) {
key = decrypt(key, salt, password);
}
return parseKey(key);
}