mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-23 04:42:06 +01:00
Fix OpenPgpV4Fingerprint.getKeyId()
This commit is contained in:
parent
ea6f89e2bc
commit
fe52a7f398
1 changed files with 4 additions and 12 deletions
|
@ -16,10 +16,8 @@
|
||||||
package org.pgpainless.key;
|
package org.pgpainless.key;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||||
|
@ -89,17 +87,11 @@ public class OpenPgpV4Fingerprint implements CharSequence, Comparable<OpenPgpV4F
|
||||||
* @return key id
|
* @return key id
|
||||||
*/
|
*/
|
||||||
public long getKeyId() {
|
public long getKeyId() {
|
||||||
|
byte[] bytes = Hex.decode(toString().getBytes(Charset.forName("UTF-8")));
|
||||||
|
ByteBuffer buf = ByteBuffer.wrap(bytes);
|
||||||
|
buf.position(12);
|
||||||
|
return buf.getLong();
|
||||||
|
|
||||||
byte[] bytes = new BigInteger(toString(), 16).toByteArray();
|
|
||||||
if (bytes.length != toString().length() / 2) {
|
|
||||||
bytes = Arrays.copyOfRange(bytes, 1, bytes.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] lower8Bytes = Arrays.copyOfRange(bytes, 12, 20);
|
|
||||||
ByteBuffer byteBuffer = ByteBuffer.allocate(8);
|
|
||||||
byteBuffer.put(lower8Bytes);
|
|
||||||
byteBuffer.flip();
|
|
||||||
return byteBuffer.getLong();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue