public static boolean isPubKeyCanonical ( byte [ ] pubkey ) { if ( pubkey [ 0 ] == 0x04 ) { // Uncompressed pubkey if ( pubkey . length != 65 ) return false ; } else if ( pubkey [ 0 ] == 0x02 || pubkey [ 0 ] == 0x03 ) { // Compressed pubkey if ( pubkey . length != 33 ) return false ; } else return false ; return true ; }
Returns true if the given pubkey is canonical i . e . the correct length taking into account compression .