java encrypted string cannot be stored in DB

后端 未结 1 971
情深已故
情深已故 2021-01-03 12:37

Trying to use the javax.crypto library to encrypt a string and store it in the database (Oracle). I will need to decrypt this string later, so I need a two-way algorithm. <

1条回答
  •  醉梦人生
    2021-01-03 13:03

    When you encrypt data you are turning it into binary data. It sounds like you are trying to store it as character data, which is a bad idea.

    You really have two options;

    1. Encode the encrypted binary data using a binary-to-text scheme such as Base64. You can then store the encoded data as character data. When you want to retrieve it you read the character data and decode (text to binary) before decrypting.

    2. Store the encrypted binary data as binary (for example as a BLOB).

    0 讨论(0)
提交回复
热议问题