com.threerings.presents.util
Class SecureUtil

java.lang.Object
  extended by com.threerings.presents.util.SecureUtil

public class SecureUtil
extends Object

Security utilities for performing secure authentication.


Field Summary
protected static SecureRandom _rand
           
protected static byte[] IV
          Our initialization vector.
protected static IvParameterSpec IVPS
           
protected static char SPLIT
          Our split character.
static int VERSION
          The version of our security protocol (for backwards compatability with older clients).
 
Constructor Summary
SecureUtil()
           
 
Method Summary
static boolean ciphersSupported(PrivateKey key)
          Returns true if we can generate our ciphers.
static boolean ciphersSupported(PublicKey key)
          Returns true if we can generate our ciphers.
static byte[] createRandomKey(int length)
          Creates a random key.
static byte[] decryptBytes(PrivateKey key, byte[] encrypted, byte[] salt)
          Decrypts a secret key and checks for tailing salt.
static byte[] encryptBytes(PublicKey key, byte[] secret, byte[] salt)
          Encrypts a secret key and salt with a public key.
static KeyPair genRSAKeyPair(int bits)
          Creates an RSA key pair.
static Cipher getAESCipher(int mode, byte[] key)
          Creates our AES cipher.
static Cipher getRSACipher(int mode, Key key)
          Creates our RSA cipher.
static Cipher getRSACipher(PrivateKey key)
          Creates our RSA cipher.
static Cipher getRSACipher(PublicKey key)
          Creates our RSA cipher.
static String RSAKeyToString(PrivateKey key)
          Converts an key to a string suitable for a properties file.
static String RSAKeyToString(PublicKey key)
          Converts an key to a string suitable for a properties file.
static PrivateKey stringToRSAPrivateKey(String str)
          Creates a private key from the supplied string.
static PublicKey stringToRSAPublicKey(String str)
          Creates a public key from the supplied string.
static byte[] xorBytes(byte[] data, byte[] key)
          XORs a byte array against a key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final int VERSION
The version of our security protocol (for backwards compatability with older clients).

See Also:
Constant Field Values

_rand

protected static final SecureRandom _rand

SPLIT

protected static final char SPLIT
Our split character.

See Also:
Constant Field Values

IV

protected static final byte[] IV
Our initialization vector.


IVPS

protected static final IvParameterSpec IVPS
Constructor Detail

SecureUtil

public SecureUtil()
Method Detail

getAESCipher

public static Cipher getAESCipher(int mode,
                                  byte[] key)
Creates our AES cipher.


getRSACipher

public static Cipher getRSACipher(PrivateKey key)
Creates our RSA cipher.


getRSACipher

public static Cipher getRSACipher(PublicKey key)
Creates our RSA cipher.


getRSACipher

public static Cipher getRSACipher(int mode,
                                  Key key)
Creates our RSA cipher.


genRSAKeyPair

public static KeyPair genRSAKeyPair(int bits)
Creates an RSA key pair.


RSAKeyToString

public static String RSAKeyToString(PublicKey key)
Converts an key to a string suitable for a properties file.


RSAKeyToString

public static String RSAKeyToString(PrivateKey key)
Converts an key to a string suitable for a properties file.


stringToRSAPublicKey

public static PublicKey stringToRSAPublicKey(String str)
Creates a public key from the supplied string.


stringToRSAPrivateKey

public static PrivateKey stringToRSAPrivateKey(String str)
Creates a private key from the supplied string.


ciphersSupported

public static boolean ciphersSupported(PrivateKey key)
Returns true if we can generate our ciphers.


ciphersSupported

public static boolean ciphersSupported(PublicKey key)
Returns true if we can generate our ciphers.


createRandomKey

public static byte[] createRandomKey(int length)
Creates a random key.


encryptBytes

public static byte[] encryptBytes(PublicKey key,
                                  byte[] secret,
                                  byte[] salt)
Encrypts a secret key and salt with a public key.


decryptBytes

public static byte[] decryptBytes(PrivateKey key,
                                  byte[] encrypted,
                                  byte[] salt)
Decrypts a secret key and checks for tailing salt.

Returns:
the secret key, or null on failure or non-matching salt.

xorBytes

public static byte[] xorBytes(byte[] data,
                              byte[] key)
XORs a byte array against a key.