public static void main(String[] args) throws Exception {

        // Generate public/private key pair
        KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
        keyGen.initialize(2048);
        KeyPair pair = keyGen.generateKeyPair();
        java.security.PublicKey pk = pair.getPublic();

        // Use the default rest client
        TwilioRestClient client =
            new TwilioRestClient.Builder(ACCOUNT_SID, AUTH_TOKEN)
                .build();

        // Create a public key and signing key using the default client
        PublicKey key = PublicKey.creator(
            Base64.encodeBase64String(pk.getEncoded())
        ).setFriendlyName("Public Key").create(client);

        NewSigningKey signingKey = NewSigningKey.creator().create(client);

        // Switch to validation client as the default client
        TwilioRestClient validationClient = new TwilioRestClient.Builder(signingKey.getSid(), signingKey.getSecret())
            .accountSid(ACCOUNT_SID)
            .httpClient(new ValidationClient(ACCOUNT_SID, key.getSid(), signingKey.getSid(), pair.getPrivate()))
            .build();

        // Make REST API requests
        Iterable<Message> messages = Message.reader().read(validationClient);
        for (Message message : messages) {
            System.out.println(message.getBody());
        }

        Message message = Message.creator(
            new PhoneNumber("+1XXXXXXXXXX"),
            new PhoneNumber("+1XXXXXXXXXX"),
            "Public Key Client Validation Test"
        ).create(validationClient);
        System.out.println(message.getSid());
    }
public static void main ( String [ ] args ) throws Exception { KeyPairGenerator keyGen = KeyPairGenerator . getInstance ( "RSA" ) ; keyGen . initialize ( 2048 ) ; KeyPair pair = keyGen . generateKeyPair ( ) ; java . security . PublicKey pk = pair . getPublic ( ) ; TwilioRestClient client = new TwilioRestClient . Builder ( ACCOUNT_SID , AUTH_TOKEN ) . build ( ) ; PublicKey key = PublicKey . creator ( Base64 . encodeBase64String ( pk . getEncoded ( ) ) ) . setFriendlyName ( "Public Key" ) . create ( client ) ; NewSigningKey signingKey = NewSigningKey . creator ( ) . create ( client ) ; TwilioRestClient validationClient = new TwilioRestClient . Builder ( signingKey . getSid ( ) , signingKey . getSecret ( ) ) . accountSid ( ACCOUNT_SID ) . httpClient ( new ValidationClient ( ACCOUNT_SID , key . getSid ( ) , signingKey . getSid ( ) , pair . getPrivate ( ) ) ) . build ( ) ; Iterable < Message > messages = Message . reader ( ) . read ( validationClient ) ; for ( Message message : messages ) { System . out . println ( message . getBody ( ) ) ; } Message message = Message . creator ( new PhoneNumber ( "+1XXXXXXXXXX" ) , new PhoneNumber ( "+1XXXXXXXXXX" ) , "Public Key Client Validation Test" ) . create ( validationClient ) ; System . out . println ( message . getSid ( ) ) ; }
Example Twilio usage.

@param args command line args
@throws TwiMLException if unable to generate TwiML