Created
April 5, 2013 19:06
-
-
Save schleichardt/5321776 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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