Simple algorithm for mixing/obfuscating a string with pre-defined chars

后端 未结 5 674
北恋
北恋 2021-01-31 05:39

I have a string as follows:

  • Its length is 10.
  • It represents base 36 and as such includes digits and uppercase letters.
  • The origin of the st
5条回答
  •  青春惊慌失措
    2021-01-31 06:19

    Unless this is a homework assignment I'd suggest you to use Base64 encoding: new sun.misc.BASE64Encoder().encode(string.getBytes()).

    This does not encrypt string but makes it unreadable.

    If you really want to encrypt the string use java cryptography API, e.g:

            Cipher cipher = Cipher.getInstance("DES");
            cipher.init(Cipher.ENCRYPT_MODE, password);
            String encrypedStr = base64encoder.encode(cipher.doFinal(cleartext));
    

    Now encryptedString is encrypted and stored in base64 format.

    You can easily find how to decrypt the string back. Good luck.

提交回复
热议问题