PGPKeyUtil { public static boolean isValidKeyId( String keyId ) { if ( keyId == null ) { return false; } try { Hex.decodeHex( keyId.toCharArray() ); switch ( keyId.length() ) { case HEX_SHORT_KEY_ID_LENGTH: case HEX_LONG_KEY_ID_LENGTH: case HEX_V4_FINGERPRINT_LENGTH: return true; case HEX_V3_FINGERPRINT_LENGTH: default: } } catch ( DecoderException ex ) { LOG.info( "Invalid hex formatted key id", ex ); } return false; }  static String encodeNumericKeyId( long keyId ); static String getKeyId( String fingerprint ); static String getFingerprint( byte[] fingerprint ); static String getShortKeyId( String fingerprint ); static boolean isFingerprint( String keyId ); static boolean isLongKeyId( String keyId ); static boolean isShortKeyId( String keyId ); static boolean isValidKeyId( String keyId ); static String exportAscii( PGPPublicKey pgpKey ); static PGPPublicKey readPublicKey( String armoredKey ); static PGPPublicKey readPublicKey( InputStream instr ); static PGPPublicKeyRing readPublicKeyRing( byte[] keyMaterial ); PGPPublicKeyRing getPublicKeyRing( byte[] keyMaterial ); static PGPPublicKeyRing readPublicKeyRing( String armoredKey ); static PGPPublicKeyRing readPublicKeyRing( InputStream instr ); static boolean isValidPublicKeyring( String publicKey ); static PGPSecretKeyRing readSecretKeyRing( byte[] keyMaterial ); PGPSecretKeyRing getSecretKeyRing( byte[] keyMaterial ); static ByteArrayInputStream readSecretKeyRingInputStream( byte[] keyMaterial ); static PGPSecretKeyRing readSecretKeyRing( InputStream instr ); static PGPPublicKey readPublicKey( PGPPublicKeyRing keyRing ); static PGPSecretKey readSecretKey( PGPSecretKeyRing keyRing ); static final int HEX_SHORT_KEY_ID_LENGTH; static final int HEX_LONG_KEY_ID_LENGTH; static final int HEX_V3_FINGERPRINT_LENGTH; static final int HEX_V4_FINGERPRINT_LENGTH; }
@Test public void testIsValidKey() throws Exception { assertTrue( PGPKeyUtil.isValidKeyId( longKeyId ) ); assertFalse( PGPKeyUtil.isValidKeyId( "blablabla" ) ); }