public static byte [ ] signatureToKeyBytes ( byte [ ] messageHash , String signatureBase64 ) throws SignatureException { byte [ ] signatureEncoded ; try { signatureEncoded = Base64 . decode ( signatureBase64 ) ; } catch ( RuntimeException e ) { // This is what you get back from Bouncy Castle if base64 doesn't decode :( throw new SignatureException ( "Could not decode base64" , e ) ; } // Parse the signature bytes into r/s and the selector value. if ( signatureEncoded . length < 65 ) throw new SignatureException ( "Signature truncated, expected 65 bytes and got " + signatureEncoded . length ) ; return signatureToKeyBytes ( messageHash , ECDSASignature . fromComponents ( Arrays . copyOfRange ( signatureEncoded , 1 , 33 ) , Arrays . copyOfRange ( signatureEncoded , 33 , 65 ) , ( byte ) ( signatureEncoded [ 0 ] & 0xFF ) ) ) ; }
Given a piece of text and a message signature encoded in base64 returns an ECKey containing the public key that was used to sign it . This can then be compared to the expected public key to determine if the signature was correct .