Encrypting numeric value as encrypted numeric value

Hi,

I am Using Sun JCE (DES algorithm) for encryption. My requirement is to read data from DB2 and encrypt and insert it to an Microsoft Access database.

I am sucessfully able to encrypt character data types and able to store it in the MS Access.

But for numeric data i am able to encrypt but not able to store in access since it contain non numeric character.

I can not modify the data type in MS Access also, since the application using this database will lose its functionality. I am attaching few line of code which i am using for encryption.

Is there any solution to achive my requirement? Please let me know.

Thanks

GS

public String encrypt(String data) throws Exception {

try {

// Our cleartext as bytes. Use UTF8 as the standard

byte[] cleartext = data.getBytes("UTF8");

// Encrypt the cleartext

byte[] ciphertext = _encryptionCipher.doFinal(cleartext);

String str = null;

BASE64Encoder b64nCoder = new BASE64Encoder();

str = b64nCoder.encode(ciphertext);

// Return a String representation of the cipher text

String eStr = new String(ciphertext);

return str;

} catch (IllegalBlockSizeException e) {

throw (e);

} catch (BadPaddingException e) {

throw (e);

}

}

[1330 byte] By [gsuba] at [2007-9-30 1:32:14]
# 1

For instance, say that you have a numeric value from 0 to 999,999,999 (it fits a long, that has 8 bytes)

- Convert the value to bytes (00 00 00 00 3B 9A C9 FF)

- Encrypt it (for instance, if you are using DES/ECB you will get a value like CE 21 04 1B 07 85 37 ED)

- Convert the bytes to a long (CE21041B078537ED is in decimal -3593586513528145939)

- Save the value as a numeric value (well, the decimal value is very big... Sorry)

For decimal values (like 1,234.567) you can try using the same thing, but scaling all your values (for instance, if the values are currencies, you can try multiply all by 100 or 10000, and using the integer or long value).

edsonwa at 2007-7-16 6:09:03 > top of Java-index,Security,Cryptography...