D
DougJrs
I am working on a java RSA encryption/decryption program. Currently
any non-alpha or numeric character is converted into a /. For example
if I take the string
"<XML tag>[email protected]</xml tag><xm2>data12345</xm2>"
and encrypt and decrypt I get
"/XML/tag/email/address/domain/com//xml/tag//xm2/data12345//xm2/x "
when I decrypt it.
Can anyone help?
Thanks in advance!
Doug
Here is my code:
Security.addProvider(new
org.bouncycastle.jce.provider.BouncyCastleProvider());
RSAEncryptUtil cipher = new RSAEncryptUtil();
KeyPair key;
RSAPublicKey PublicKey;
RSAPrivateKey PrivateKey;
key = cipher.generateKey();
PublicKey = (RSAPublicKey)key.getPublic();
PrivateKey = (RSAPrivateKey)key.getPrivate();
String TestMessage = "<XML tag>[email protected]</xml
tag><xm2>data12345</xm2>";
BASE64Decoder b642 = new BASE64Decoder();
byte[] cipherText = b642.decodeBuffer(TestMessage);
out.println("<p>test before cipher: " + cipherText);
Cipher cipher2 = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher2.init(Cipher.ENCRYPT_MODE, key.getPublic());
cipherText = cipher2.doFinal(cipherText);
out.println("<p> Encrypted text is: " + cipherText);
byte[] dectyptedText = null;
Cipher cipher3 = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher3.init(Cipher.DECRYPT_MODE, key.getPrivate());
dectyptedText = cipher3.doFinal(cipherText);
BASE64Encoder b64 = new BASE64Encoder();
out.println("<p> Unencrypted text is: " +
b64.encode(dectyptedText));
And here is the output that it creates:
test before cipher: [B@104474
Encrypted text is: [B@1fe5c54
Unencrypted text is: /XML/tag/email/address/domain/com//xml/tag//xm2/
data12345//xm2/x
any non-alpha or numeric character is converted into a /. For example
if I take the string
"<XML tag>[email protected]</xml tag><xm2>data12345</xm2>"
and encrypt and decrypt I get
"/XML/tag/email/address/domain/com//xml/tag//xm2/data12345//xm2/x "
when I decrypt it.
Can anyone help?
Thanks in advance!
Doug
Here is my code:
Security.addProvider(new
org.bouncycastle.jce.provider.BouncyCastleProvider());
RSAEncryptUtil cipher = new RSAEncryptUtil();
KeyPair key;
RSAPublicKey PublicKey;
RSAPrivateKey PrivateKey;
key = cipher.generateKey();
PublicKey = (RSAPublicKey)key.getPublic();
PrivateKey = (RSAPrivateKey)key.getPrivate();
String TestMessage = "<XML tag>[email protected]</xml
tag><xm2>data12345</xm2>";
BASE64Decoder b642 = new BASE64Decoder();
byte[] cipherText = b642.decodeBuffer(TestMessage);
out.println("<p>test before cipher: " + cipherText);
Cipher cipher2 = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher2.init(Cipher.ENCRYPT_MODE, key.getPublic());
cipherText = cipher2.doFinal(cipherText);
out.println("<p> Encrypted text is: " + cipherText);
byte[] dectyptedText = null;
Cipher cipher3 = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher3.init(Cipher.DECRYPT_MODE, key.getPrivate());
dectyptedText = cipher3.doFinal(cipherText);
BASE64Encoder b64 = new BASE64Encoder();
out.println("<p> Unencrypted text is: " +
b64.encode(dectyptedText));
And here is the output that it creates:
test before cipher: [B@104474
Encrypted text is: [B@1fe5c54
Unencrypted text is: /XML/tag/email/address/domain/com//xml/tag//xm2/
data12345//xm2/x