0

I need an encryption algorithm for JAVA but I am storing it in a system which has a few reserved characters. As encryption generally generates all characters, does anyone know a strategy to encrypt without hitting reserved special characters.

  • 2
    Encrypted data is usually binary, i.e. a `byte[]`, and is most often encoded in [**Base64**](https://docs.oracle.com/javase/8/docs/api/java/util/Base64.html) when it needs to be stored/transmitted in text form. – Andreas Oct 24 '20 at 00:29
  • Be more specific and focused if you expect any useful answers. – Spectric Oct 24 '20 at 00:41
  • A XOR encryption is easy to implement and the way to go for hacking a system :p – paladin Oct 24 '20 at 02:46
  • Most encryption algorithms work on numbers (many of them on 64-bit numbers even), so "characters" first undergo some transformation to a number. The result of the encryption is also a number. You can then decide, if you want, to encode that number again as characters or just store it as a binary number. When storing as characters, base64 is the most common approach for converting the number to characters. You could also define a custom approach (you could escape characters if only a few are forbidden) but it would be very hard to extract data from the database without your app. just do base64. – Erwin Bolwidt Oct 24 '20 at 03:50
  • 2
    @ErwinBolwidt "Most encryption algorithms work on numbers (many of them on 64-bit numbers even)". Er no, most algorithms operate on bits or rather bytes; message input for cryptographic algorithms are generally specified as binary in cryptographic specifications (and dumbed down to bytes for most implementations). However, the idea to simply use an encoding such as base 64 is of course fine :) – Maarten Bodewes Oct 24 '20 at 06:30
  • @MaartenBodewes Most encryption algorithms (ciphers) are block ciphers. Until AES, almost all had 64-bit block sizes; AES uses 128-bit block sizes nowadays. That's why we have padding algorithms, in case the text isn't a multiple of the block size. https://en.m.wikipedia.org/wiki/Block_size_(cryptography). Hence encryption algorithms do not work on bits/bytes, but on fixed-size blocks that are larger. – Erwin Bolwidt Oct 24 '20 at 08:54
  • OK, implementation wise they are generally 32 or 64 bit integers, but no higher level API (such as the JCA) will actually use those directly. And then those are generally not really used in numbers (shift operations, XOR, modulo 2^32 addition etc.). There is definitely no conversion to numbers necessary; if you have characters then you can use character encoding to bytes, if you have bytes you can use base 64 (or base64url, or hex) to encode to characters. – Maarten Bodewes Oct 24 '20 at 15:06
  • What do you think that a character encoding is but a conversion of characters to numbers? – Erwin Bolwidt Oct 25 '20 at 03:47

0 Answers0