How to encrypt/decrypt a file in Java?

前端 未结 6 1501
滥情空心
滥情空心 2021-01-16 09:07

I am writing a Java application which can \"encrypt\" and consequently \"decrypt\" whatever binary file.

I am just a beginner in the \"cryptography\" area so I would

6条回答
  •  北荒
    北荒 (楼主)
    2021-01-16 09:49

    A really simple way to use a password to encrypt is to use XOR, here is some pseudo code

    for(byte in file)
    {
        Byte newByte = byte ^ (byte) password[i];
        outputFile.write(newByte);
        i = (i + 1) password.length();
    }
    

    This is based on the identity that (x XOR y) XOR y = x, all you need to do is encrypt/decrypt with the same password.

提交回复
热议问题