org.keyczar.Signer Java Examples

The following examples show how to use org.keyczar.Signer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HMACCSRFProtection.java    From Anti-CSRF-Library with Apache License 2.0 6 votes vote down vote up
private String handleCSRFTokenGeneration(String unhashedToken) throws CSRFTokenGenerationException
{
	try
	{			
		Date currentTime = new Date();
		String currentTimeString = String.valueOf( currentTime.getTime() );
		KeyczarWrapper keyczarWrapper = ConfigUtil.getKeyczarWrapper();
		Signer csrfSigner = keyczarWrapper.getCSRFSigner();
		String csrfHmac = csrfSigner.sign(unhashedToken + ":" + currentTimeString);
		
		return csrfHmac + ":" + currentTimeString;
	}
	catch( KeyczarException ex ) 
	{
		String err = "Encountered error creating HMAC signature with the Keyczar library"
				+ ", exceptionmessage=" + ex.getMessage();
		LOG.info(err);
		throw new CSRFTokenGenerationException(err);
	}
}
 
Example #2
Source File: KeyczarKeyFactory.java    From passopolis-server with GNU General Public License v3.0 5 votes vote down vote up
public KeyczarPrivateKey(KeyczarReader encryptionReader, KeyczarReader signingReader)
    throws KeyczarException {
  super(encryptionReader, signingReader);

  crypter = new Crypter(encryptionReader);
  signer = new Signer(signingReader);
}
 
Example #3
Source File: SecretsBundle.java    From passopolis-server with GNU General Public License v3.0 5 votes vote down vote up
/** Loads secrets from path. */
public SecretsBundle(String path) {
  String subPathString = new File(path, SIGNING_RELATIVE_PATH).getPath();
  logger.info("loading signing key from {}", subPathString);
  try {
    signingKey = new Signer(new KeyczarFileReader(subPathString));
  } catch (KeyczarException e) {
    throw new RuntimeException("Unable to load signing key", e);
  }
}
 
Example #4
Source File: SecretsBundle.java    From passopolis-server with GNU General Public License v3.0 5 votes vote down vote up
/** Returns a new SecretsBundle with random test secrets. */
public static SecretsBundle generateForTest() {
  try {
    Signer signer = new Signer(Util.generateKeyczarReader(
        DefaultKeyType.HMAC_SHA1, KeyPurpose.SIGN_AND_VERIFY));
    return new SecretsBundle(signer);
  } catch (KeyczarException e) {
    throw new RuntimeException("Error generating signing key", e);
  }
}
 
Example #5
Source File: RoundTripper.java    From passopolis-server with GNU General Public License v3.0 5 votes vote down vote up
private static void sign(String keyPath, String message, String outpath) throws KeyczarException, IOException {
  Signer key = new Signer(Util.readJsonFromPath(keyPath));
  System.out.println("signing message length " + message.length());
  String output = key.sign(message);

  Files.write(output, new File(outpath), Charsets.UTF_8);
}
 
Example #6
Source File: KeyczarWrapper.java    From Anti-CSRF-Library with Apache License 2.0 5 votes vote down vote up
public KeyczarWrapper(String hmacKeyfile) throws CSRFSignerException
{
	try {
		csrfSigner = new Signer(hmacKeyfile);
	} catch (KeyczarException e) {
		throw new CSRFSignerException(e);
	}
}
 
Example #7
Source File: SecretsBundle.java    From passopolis-server with GNU General Public License v3.0 4 votes vote down vote up
private SecretsBundle(Signer signingKey) {
  this.signingKey = checkNotNull(signingKey);
}
 
Example #8
Source File: KeyczarWrapper.java    From Anti-CSRF-Library with Apache License 2.0 4 votes vote down vote up
public Signer getCSRFSigner()
{
	return this.csrfSigner;
}
 
Example #9
Source File: DSA.java    From JavaSecurity with Apache License 2.0 4 votes vote down vote up
private static String sign(String initialText) throws KeyczarException {
    Signer signer = new Signer(KEYSET_PATH);
    return signer.sign(initialText);
}