org.apache.shindig.common.crypto
Class BasicBlobCrypter

java.lang.Object
  extended by org.apache.shindig.common.crypto.BasicBlobCrypter
All Implemented Interfaces:
BlobCrypter

public class BasicBlobCrypter
extends Object
implements BlobCrypter

Simple implementation of BlobCrypter.


Field Summary
static int MASTER_KEY_MIN_LEN
          minimum length of master key
 TimeSource timeSource
           
static String TIMESTAMP_KEY
          Key used for time stamp (in seconds) of data
 
Constructor Summary
BasicBlobCrypter(byte[] masterKey)
          Builds a BlobCrypter from the specified master key
BasicBlobCrypter(File keyfile)
          Creates a crypter based on a key in a file.
 
Method Summary
 Map<String,String> unwrap(String in, int maxAgeSec)
          Unwraps a blob.
 String wrap(Map<String,String> in)
          Time stamps, encrypts, and signs a blob.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TIMESTAMP_KEY

public static final String TIMESTAMP_KEY
Key used for time stamp (in seconds) of data

See Also:
Constant Field Values

MASTER_KEY_MIN_LEN

public static final int MASTER_KEY_MIN_LEN
minimum length of master key

See Also:
Constant Field Values

timeSource

public TimeSource timeSource
Constructor Detail

BasicBlobCrypter

public BasicBlobCrypter(File keyfile)
                 throws IOException
Creates a crypter based on a key in a file. The key is the first line in the file, whitespace trimmed from either end, as UTF-8 bytes. The following *nix command line will create an excellent key:
 dd if=/dev/random bs=32 count=1  | openssl base64 > /tmp/key.txt
 

Throws:
IOException - if the file can't be read.

BasicBlobCrypter

public BasicBlobCrypter(byte[] masterKey)
Builds a BlobCrypter from the specified master key

Parameters:
masterKey -
Method Detail

wrap

public String wrap(Map<String,String> in)
            throws BlobCrypterException
Description copied from interface: BlobCrypter
Time stamps, encrypts, and signs a blob.

Specified by:
wrap in interface BlobCrypter
Parameters:
in - name/value pairs to encrypt
Returns:
a base64 encoded blob
Throws:
BlobCrypterException - when crypto errors occur

unwrap

public Map<String,String> unwrap(String in,
                                 int maxAgeSec)
                          throws BlobCrypterException
Description copied from interface: BlobCrypter
Unwraps a blob.

Specified by:
unwrap in interface BlobCrypter
Parameters:
in - blob
maxAgeSec - maximum age for the blob
Returns:
the name/value pairs, including the origin timestamp.
Throws:
BlobExpiredException - if the blob is too old to be accepted.
BlobCrypterException - if the blob can't be decoded.


Copyright © 2007-2012. All Rights Reserved.