jetbrains.buildServer.serverSide.crypt
Class RSACipher

java.lang.Object
  extended by jetbrains.buildServer.serverSide.crypt.RSACipher

public class RSACipher
extends java.lang.Object

Utility class intended to simplify RSA encryption / decryption.


Method Summary
static java.lang.String decryptData(java.lang.String hexEncoded)
          Decrypts hex encoded byte array with help of RSA private key.
static java.lang.String decryptWebRequestData(java.lang.String hexEncoded)
          Decrypts hex encoded JavaScript encrypted data.
static java.lang.String encryptData(java.lang.String plain)
          Encrypts specified string, and returns hex representation of the encrypted data
static java.lang.String encryptData(java.lang.String plain, java.security.PublicKey pubKey)
          Encrypts data using the specified public key
static java.lang.String encryptDataForWeb(java.lang.String plain)
          Encrypts specified string, and returns hex representation of the encrypted data.
static void generateKeys()
          Generates new public and private keys and stores them in static fields.
static java.lang.String getHexEncodedPublicKey()
          Returns hex representation of the public key
static java.lang.String getHexEncodedPublicKeyExponent()
          Returns hex representation of the public key exponent
static java.security.PublicKey recreateKey(java.lang.String hexModulus, java.lang.String hexExponent)
          Recreates public key from hex encoded modulus & exponent.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

generateKeys

public static void generateKeys()
Generates new public and private keys and stores them in static fields.


decryptData

public static java.lang.String decryptData(java.lang.String hexEncoded)
                                    throws DecryptionFailedException
Decrypts hex encoded byte array with help of RSA private key.

Parameters:
hexEncoded - hex encoded encrypted data
Returns:
decrypted string
Throws:
DecryptionFailedException - if decryption failed

decryptWebRequestData

@Nullable
public static java.lang.String decryptWebRequestData(java.lang.String hexEncoded)
                                              throws DecryptionFailedException
Decrypts hex encoded JavaScript encrypted data.

Parameters:
hexEncoded - hex encoded encrypted byte array
Returns:
decrypted string
Throws:
DecryptionFailedException - if decryption failed

encryptData

@Nullable
public static java.lang.String encryptData(java.lang.String plain)
                                    throws EncryptionFailedException
Encrypts specified string, and returns hex representation of the encrypted data

Parameters:
plain - text to encrypt
Returns:
hex representation of the encrypted data
Throws:
EncryptionFailedException - if encryption failed

encryptDataForWeb

public static java.lang.String encryptDataForWeb(java.lang.String plain)
                                          throws EncryptionFailedException
Encrypts specified string, and returns hex representation of the encrypted data. It differs from encryptData(String) in that it stores length of the encrypted string as a last byte into byte array before encryption

Parameters:
plain - text to encrypt
Returns:
hex representation of the encrypted data
Throws:
EncryptionFailedException - if encryption failed

encryptData

@Nullable
public static java.lang.String encryptData(java.lang.String plain,
                                                    java.security.PublicKey pubKey)
                                    throws EncryptionFailedException
Encrypts data using the specified public key

Parameters:
plain - text to encrypt
pubKey - public key
Returns:
data encrypted with specified public key in hex form
Throws:
EncryptionFailedException - if encryption failed

getHexEncodedPublicKey

public static java.lang.String getHexEncodedPublicKey()
Returns hex representation of the public key

Returns:
hex representation of the public key

getHexEncodedPublicKeyExponent

public static java.lang.String getHexEncodedPublicKeyExponent()
Returns hex representation of the public key exponent

Returns:
hex representation of the public key exponent

recreateKey

public static java.security.PublicKey recreateKey(java.lang.String hexModulus,
                                                  java.lang.String hexExponent)
                                           throws java.security.InvalidKeyException
Recreates public key from hex encoded modulus & exponent.

Parameters:
hexModulus - hex encoded modulus
hexExponent - hex encoded exponent
Returns:
recreated public key
Throws:
java.security.InvalidKeyException - if key recreation failed