From: Ingo V. <ing...@gm...> - 2009-01-13 16:08:59
|
Hello, I've a (understanding?-) problem with MessageFactory. If I execute following Code, I don't get back the same String as I assigned the variable "data". It alway append "\r\n" at the end of the string. I tried to debug this and found, that this appendix comes from MessageFactory (mf.generateMessages(inp)). The Stream "inp" that were passed to mf.generateMessages does not contain this characters. If I use the Collection co (commended out), I found there this appendix too. The same Problem I get, if I use the Cryptix examples (GenerateAndWriteKey.java, Encrypt.java, Decrypt.java) and a single lined string as TestString msg in Encrypt.java The Problem is, that that decrypted Message is not the original Message before encryption.. I want hash and compare the message before and after ... but so I get never the same hash. If the "\r\n" is every time appanded, than I can remove it, but what, when original message ends with a new line .... Then its no second new line appended :-( I also found the test AsciiLastLineTest.java, but it's not commended ... Thanx for helping Ingo CODE: ########################################### package MFTest; import cryptix.message.MessageFactory; import cryptix.message.LiteralMessage; import java.io.InputStream; import java.io.ByteArrayInputStream; public class MFTest { public static void main(String[] args) { java.security.Security.addProvider(new cryptix.openpgp.provider.CryptixOpenPGP()); String data = "AAAAAAAA"; try { MessageFactory mf = MessageFactory.getInstance("OpenPGP"); InputStream inp = new ByteArrayInputStream(data.getBytes("UTF-8")); //Collection co = mf.generateMessages(inp); LiteralMessage msg = (LiteralMessage) mf.generateMessages(inp).iterator().next(); System.out.println(":" + data + ":"); System.out.println(":" + msg.getTextData() + ":"); } catch (Exception e) { System.out.println(e.toString()); } } } ########################################### OUTPUT: :AAAAAAAA: :AAAAAAAA : ########################################## |