mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-22 20:32:05 +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;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||
|
@ -89,17 +87,11 @@ public class OpenPgpV4Fingerprint implements CharSequence, Comparable<OpenPgpV4F
|
|||
* @return key id
|
||||
*/
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue