GetPersonalICode

Updated at:

Retrieves or generates a personal identification number for a user.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

No authorization for this operation. If you encounter issues with this operation, contact technical support.

Request syntax

POST  HTTP/1.1

Request parameters

Parameter

Type

Required

Description

Example

QuickBIUserId

string

No

The Quick BI user ID.

asdasda

Response elements

Element

Type

Description

Example

object

RequestId

string

The request ID.

BCE45E6D-9304-4F94-86BB-5A772B1615FF

Result

object

The AccessKey model.

{ "icode": "V2Yc/dMFWBwTKLNCNxgnN****z***5ARu", "icodeKey": "b6f3***32a62936", "type": 1 }

Type

integer

The AccessKey type. Currently, only the value 1 is supported, which indicates a personal AccessKey.

1

Icode

string

SK

V2Yc/dMFWBwTKLNCNxgnN****z***5ARu

IcodeKey

string

AK

asdasd

Success

boolean

Indicates whether the request is successful. Valid values:

  • true: The request is successful.

  • false: The request fails.

true

The SK data must be decrypted before use. If you have not configured an organization key, contact Quick BI support to configure the organization key. You must provide your Base64-encoded key.

Important The ciphertext returned by Quick BI is encrypted by using AES symmetric encryption. Decrypt the ciphertext by using the following parameters: Algorithm/Mode/Padding: AES/ECB/PKCS5Padding. Key length: AES-128 (16 bytes). Ciphertext processing: The icode ciphertext string returned by the API is Base64-encoded. Decode the Base64 string to obtain the ciphertext bytes, and then perform AES decryption. Character set: Convert the decrypted plaintext bytes to a string by using UTF-8. The ECB mode does not require an IV (initialization vector). Decryption steps: Base64-decode your key -> Base64-decode the ICode ciphertext -> Decrypt by using AES/ECB/PKCS5Padding -> Convert to a string by using UTF-8.

Sample Java code for decryption:

package com.example.demo.openapi;

import javax.crypto.BadPaddingException;

import javax.crypto.Cipher;

import javax.crypto.IllegalBlockSizeException;

import javax.crypto.NoSuchPaddingException;

import javax.crypto.spec.SecretKeySpec;

import java.nio.charset.StandardCharsets;

import java.security.GeneralSecurityException;

import java.security.InvalidKeyException;

import java.security.NoSuchAlgorithmException;

import java.util.Base64;

public class testddd {

public static final String KEY_ALGORITHM = "AES";

public static final String CIPHER_ALGORITHM = "AES/ECB/PKCS5Padding";
/**
 * Your Base64-encoded key.
 */
public static final String BASE_64 = "xxxx";

public static void main(String[] args) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
    String decrypt = decrypt("iCode-api-return", BASE_64);
    System.out.println(decrypt);
}

/**
 * Decrypts the {@code icode} returned by the API to restore the plaintext SK.
 *
 * @param cipherIcode   The {@code icode} field returned by the API, which is the Base64-encoded AES ciphertext.
 * @param base64SecretKey The key provided to Quick BI, which is the Base64-encoded 16-, 24-, or 32-byte key.
 * @return The plaintext SK.
 * @throws IcodeDecryptException Thrown when the ciphertext or key is invalid, or the key does not match. The exception message contains troubleshooting suggestions.
 */
public static String decrypt(String cipherIcode, String base64SecretKey)  {
    byte[] keyBytes;
    try {
        keyBytes = Base64.getDecoder().decode(normalize(base64SecretKey));
    } catch (IllegalArgumentException e) {
        throw new IcodeDecryptException("The key is not a valid Base64 string. Make sure that you use the Base64-encoded key, "
                + "instead of the original passphrase text.", e);
    }

    byte[] cipherBytes;
    try {
        cipherBytes = Base64.getDecoder().decode(normalize(cipherIcode));
    } catch (IllegalArgumentException e) {
        throw new IcodeDecryptException("The icode is not a valid Base64 string. Make sure that you pass the original icode field returned by the API.", e);
    }

    try {
        Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
        cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(keyBytes, KEY_ALGORITHM));
        // The SK consists of visible ASCII characters. Restoring it by using UTF-8 is consistent with the character set used for encryption on the server.
        return new String(cipher.doFinal(cipherBytes), StandardCharsets.UTF_8);
    } catch (GeneralSecurityException e) {
        throw new IcodeDecryptException("Decryption failed. Check whether the key is the same as the one used for encryption, or whether the ciphertext is truncated or tampered with.", e);
    }
}

/**
 * Base64 normalization: removes all whitespace characters (some gateways or logs may insert line breaks in long strings),
 * and restores the URL-safe variants {@code -} and {@code _} to the standard Base64 characters {@code +} and {@code /}
 * (during form transmission, {@code +} is often decoded as a space, which is also restored here).
 */
private static String normalize(String base64Text) {
    if (base64Text == null) {
        throw new IllegalArgumentException("The Base64 content cannot be empty.");
    }
    StringBuilder sb = new StringBuilder(base64Text.length());
    for (int i = 0; i < base64Text.length(); i++) {
        char c = base64Text.charAt(i);
        if (c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\f') {
            // Skip whitespace. Note that spaces in the ciphertext can only come from '+' being decoded by a form, which is handled by the following branch.
            continue;
        }
        if (c == '-') {
            sb.append('+');
        } else if (c == '_') {
            sb.append('/');
        } else {
            sb.append(c);
        }
    }
    return sb.toString();
}

/**
 * The exception that occurs during the icode decryption process.
 */
public static class IcodeDecryptException extends RuntimeException {
    public IcodeDecryptException(String message) {
        super(message);
    }

    public IcodeDecryptException(String message, Throwable cause) {
        super(message, cause);
    }
}

}

Examples

Success response

JSON format

{
  "RequestId": "BCE45E6D-9304-4F94-86BB-5A772B1615FF",
  "Result": {
    "Type": 1,
    "Icode": "V2Yc/dMFWBwTKLNCNxgnN****z***5ARu",
    "IcodeKey": "asdasd"
  },
  "Success": true
}

Error codes

HTTP status code

Error code

Error message

Description

400 Internal.System.Error An internal system error occurred. An internal system error occurred.
400 Invalid.Parameter.Error The parameter is invalid:%s. invalid parameter: ${0}.
400 Invalid.User.Organization The user is not in your organization. The user is not in your organization.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.