public boolean verifySignature ( Map < String , String > parsedMessage , PublicKey publicKey ) { boolean valid = false ; String version = parsedMessage . get ( SIGNATURE_VERSION ) ; if ( version . equals ( "1" ) ) { // construct the canonical signed string String type = parsedMessage . get ( TYPE ) ; String signature = parsedMessage . get ( SIGNATURE ) ; String signed ; if ( type . equals ( NOTIFICATION_TYPE ) ) { signed = stringToSign ( publishMessageValues ( parsedMessage ) ) ; } else if ( type . equals ( SUBSCRIBE_TYPE ) ) { signed = stringToSign ( subscribeMessageValues ( parsedMessage ) ) ; } else if ( type . equals ( UNSUBSCRIBE_TYPE ) ) { signed = stringToSign ( subscribeMessageValues ( parsedMessage ) ) ; // no difference, for now } else { throw new RuntimeException ( "Cannot process message of type " + type ) ; } valid = verifySignature ( signed , signature , publicKey ) ; } return valid ; }
Validates the signature on a Simple Notification Service message . No Amazon - specific dependencies just plain Java crypto