0

I'm working typing a program that store strings in a log file. The problem is that the characters could be more than one or only one, and arrives very fast (less than second maybe).

I'm doing an experiment, the idea is to do like a simple "text editor", that each key that you press will be stored encrypted automatically in a file in real time. Also will have emoticons, represented by "[:SMILE]" and arrives using a button, so appears . Is for that that the chars could be of lenght>=1 .

The encriptation method will be using asimetric, I dont know if RSA or PGP, what is better for that?

I want to find a good methology for encrypt it because maybe the encryption progres could be slow.

One example is use one buffer and when is full liberate it and crypt it, and append the file in crypted blocks of 1024 for example and uncrypt it using this block size.

I don't know if that is the optimized solution... How to work with crypted logs that are generated crypted and fast?

selan
  • 956
  • 3
  • 11
  • 27
  • 1
    Less than second is rather broad. Also "because maybe the encryption progres could be slow". What is this based on? guesses? Also how are you encrypting the data? What are "crypted logs"? – PeeHaa Oct 27 '15 at 21:47
  • @PeeHaa I edited the question adding more info. Its well explained now? – selan Oct 28 '15 at 07:58
  • Maybe another idea could be, not crypt at byte level, do it doing at string level and after each string receiver, crypt it, put a start and end identifier for know where start each string that must to be decrypted separatly. – selan Oct 28 '15 at 10:46

1 Answers1

0

I found two different options, both in line with a "buffer".

One is to do a buffer and send it to cipher when the buffer reaches a size. The other is do it in a temporal way, ergo, send to cipher each time (for example two second)

The first one is to create a buffer using a CharBuffer. When the buffer reaches the buffer size, it send the content using a synchronized thread to the cipher for the encription, something like that:

    public class KeyStrokeBuffer
{
  private CharBuffer buffer;
  private static final int BUFFER_SIZE = 5;

  Scanner sc;

  public KeyStrokeBuffer ()
  {
    this.buffer  = CharBuffer.allocate(BUFFER_SIZE);
    sc = new Scanner(System.in);
  }

  public void add (String s){
    int pointer = 0;
    while (pointer < s.length() &&  buffer.length() >0){
        buffer.put (s.charAt(pointer));
        pointer++;
        s.substring(1);
    }
    if (pointer != s.length()) { //This is for make the string sended always in the same size
        cipher (buffer); //This launched like a synchronized thread 
        buffer = CharBuffer.allocate(BUFFER_SIZE); 
        add(s);
    }
  }

  public void cipher (CharBuffer buffer){
    System.out.println ("Dentro cypher");
  }

The second way creates a class with a LinkedList as a buffer. In this class a thread sleeps for example 2 seconds and send the linked list to the cipher if is not empty. At the same time, a method of this class add Strings to the linked list. So we have a thread that send the linked list every "x" time and a function to add strings to this linked list.

I don't implement this yet.

In the Cipher we must to know that each block to encrypt must to have a specific width, for decrypt it correctly. Other thing is that if a lot of threads will be heavy to process.

Also I found a possible solution in this post: How to append to AES encrypted file

selan
  • 956
  • 3
  • 11
  • 27