ragflow icon indicating copy to clipboard operation
ragflow copied to clipboard

[Question]: The issue of password encryption during Web API login.

Open hejianlinhjl opened this issue 1 year ago • 3 comments

Self Checks

  • [x] I have searched for existing issues search for existing issues, including closed ones.
  • [x] I confirm that I am using English to submit this report (Language Policy).
  • [x] Non-english title submitions will be closed directly ( 非英文标题的提交将会被直接关闭 ) (Language Policy).
  • [x] Please do not modify this template :) and fill in all the required fields.

Describe your problem

When calling the web API to log in using Java, I keep getting the following response: { "code": 109, "data": false, "message": "Email and password do not match!" } Below is my password encryption method: public static String encrypt(String data, PublicKey publicKey) throws Exception { Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); cipher.init(Cipher.ENCRYPT_MODE, publicKey); byte[] encryptedBytes = cipher.doFinal(data.getBytes(StandardCharsets.UTF_8)); return Base64.getEncoder().encodeToString(encryptedBytes); }

hejianlinhjl avatar Jul 21 '25 08:07 hejianlinhjl

The RAGFlow API expects the password to be base64-encoded first, then encrypted with RSA/PKCS1 v1.5 using the server's public key (found in conf/public.pem), and finally base64-encoded again for transmission. Your Java code is missing the initial base64-encoding step before encryption, which is required for successful authentication. The correct flow is: base64-encode the password, encrypt the result with RSA/PKCS1 v1.5, then base64-encode the encrypted bytes before sending to the API. Omitting the first base64 step will cause login failures even if the encryption and key are otherwise correct. You should also ensure you are using the exact public key from the server, as mismatches or outdated keys are a common source of this error. See the frontend implementation for reference "rsaPsw" and backend decryption logic "decrypt".

A corrected Java snippet would look like:

public static String encrypt(String password, PublicKey publicKey) throws Exception {
    // Step 1: Base64-encode the password
    String base64Password = Base64.getEncoder().encodeToString(password.getBytes(StandardCharsets.UTF_8));
    // Step 2: Encrypt the base64-encoded password
    Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
    cipher.init(Cipher.ENCRYPT_MODE, publicKey);
    byte[] encryptedBytes = cipher.doFinal(base64Password.getBytes(StandardCharsets.UTF_8));
    // Step 3: Base64-encode the encrypted bytes for transmission
    return Base64.getEncoder().encodeToString(encryptedBytes);
}

Double-check that the public key you use matches the server's current public.pem. This should resolve the "Email and password do not match!" error if your credentials are correct.

To reply, just mention @dosu.


Docs are dead. Just use Dosu.

Leave Feedback Ask Dosu about ragflow Share Dosu with your team

dosubot[bot] avatar Jul 21 '25 08:07 dosubot[bot]

I'm experiencing the same issue. The Java encryption method looks correct, but I'm getting "Fail to crypt password" error. Has anyone found a solution?

HaoFu2026 avatar Sep 25 '25 02:09 HaoFu2026

Sorry for the very late reply. We’ve released many updates since then, so I wanted to check whether this issue is still happening for you. If the issue no longer exists, feel free to close this issue. Thanks!

Yannnnnnny avatar Jul 15 '26 11:07 Yannnnnnny