Skip to content

Instantly share code, notes, and snippets.

@schleichardt
Created April 5, 2013 19:06
Show Gist options
  • Save schleichardt/5321776 to your computer and use it in GitHub Desktop.
Save schleichardt/5321776 to your computer and use it in GitHub Desktop.
/**
* Answer for https://groups.google.com/forum/?fromgroups=#!topic/play-framework/MF_cQ743vv4
*/
package controllers;
import com.typesafe.config.ConfigFactory;
import play.*;
import play.libs.Crypto;
import play.mvc.*;
import java.io.UnsupportedEncodingException;
public class Application extends Controller {
public static final String MESSAGE_TO_SIGN = "hello";
public static Result index() {
return ok(MESSAGE_TO_SIGN + " signed: " + Crypto.sign(MESSAGE_TO_SIGN));
}
public static void main(String[] args) throws UnsupportedEncodingException {
System.out.println(signWithoutStartingWebServer(MESSAGE_TO_SIGN));
}
private static String signWithoutStartingWebServer(String message) throws UnsupportedEncodingException {
final Configuration configuration = new Configuration(ConfigFactory.load());
final String secret = configuration.getString("application.secret");
return Crypto.sign(message, secret.getBytes("utf-8"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment