ABHA¶
abha_dto ¶
GenerateAadhaarOtpRequest ¶
Bases: BaseModel
Request payload to initiate Aadhaar-based authentication by generating an OTP.
This is typically the first step in ABHA (Ayushman Bharat Health Account) creation or login workflows. The OTP will be sent to the mobile number linked with the Aadhaar.
Attributes:
| Name | Type | Description |
|---|---|---|
aadhaar |
str
|
The 12-digit Aadhaar number of the individual. |
VerifyOtpResponse ¶
Bases: BaseModel
Response returned after verifying the OTP sent to the user's registered mobile number.
This response includes a transaction ID (txnId) which is required for subsequent
actions such as ABHA enrollment or login.
Attributes:
| Name | Type | Description |
|---|---|---|
txnId |
str
|
Unique identifier for the authentication session. |
message |
str
|
Server response indicating verification result. |
EnrollWithAadhaar ¶
Bases: BaseModel
Request payload to enroll a user using Aadhaar OTP verification.
This request is sent after the OTP has been verified. It is used to create an ABHA account or to authenticate the user.
Attributes:
| Name | Type | Description |
|---|---|---|
otp |
str
|
One-Time Password sent to the user’s mobile. |
txnId |
str
|
Transaction ID obtained from OTP verification. |
mobile |
str
|
Mobile number to be linked with the user's ABHA profile. |
AbhaProfile ¶
Bases: BaseModel
Complete demographic and KYC profile of a user associated with their ABHA account.
This model contains all the personal and administrative details retrieved from the ABHA system after successful authentication or account creation.
Attributes:
| Name | Type | Description |
|---|---|---|
preferredAddress |
Optional[str]
|
Preferred PHR (Personal Health Record) address. |
firstName |
str
|
User's first name. |
lastName |
str
|
User's last name. |
middleName |
str
|
User's middle name. |
dateOfBirth |
Optional[str]
|
Date of birth (alias: 'dob'). |
gender |
str
|
Gender of the user (e.g., M/F/O). |
profilePhoto |
Optional[str]
|
Base64-encoded photo (alias: 'photo'). |
mobile |
str
|
Registered mobile number. |
mobileVerified |
Optional[bool]
|
Flag indicating mobile number verification status. |
email |
Optional[str]
|
Email address (if provided). |
phrAddress |
Optional[list[str]]
|
List of user's PHR addresses. |
address |
str
|
Full postal address. |
districtCode |
Optional[str]
|
District administrative code. |
stateCode |
Optional[str]
|
State administrative code. |
pinCode |
Optional[str]
|
Postal code. |
abhaType |
str
|
Type of ABHA ID (e.g., self-created, facility-created). |
stateName |
str
|
Full name of the state. |
districtName |
str
|
Full name of the district. |
ABHANumber |
str
|
User’s unique ABHA number. |
abhaStatus |
str
|
Status of the ABHA account (e.g., Active, Inactive). |
authMethods |
Optional[AuthMethodV2]
|
Available authentication methods. |
emailVerified |
Optional[bool]
|
Email verification status. |
kycPhoto |
Optional[str]
|
KYC image used for verification. |
kycVerified |
Optional[bool]
|
Whether KYC verification was successful. |
monthOfBirth |
Optional[str]
|
User's birth month. |
name |
Optional[str]
|
Full name of the user. |
subDistrictCode |
Optional[str]
|
Code for the sub-district/tehsil. |
subdistrictName |
Optional[str]
|
Name of the sub-district. |
tags |
Optional[dict[str, str]]
|
Metadata tags or flags associated with the user. |
townCode |
Optional[str]
|
Administrative town code. |
townName |
Optional[str]
|
Name of the town. |
verificationStatus |
Optional[str]
|
Status of profile verification. |
verificationType |
Optional[str]
|
Type of verification done. |
villageCode |
Optional[str]
|
Code for the village. |
villageName |
Optional[str]
|
Name of the village. |
wardCode |
Optional[str]
|
Urban ward code. |
wardName |
Optional[str]
|
Urban ward name. |
yearOfBirth |
Optional[str]
|
Year of birth. |
AbhaTokens ¶
Bases: BaseModel
Authentication tokens issued after successful login or enrollment.
These tokens are essential for making authorized requests to ABHA APIs. The access token is short-lived, while the refresh token can be used to obtain a new access token.
Attributes:
| Name | Type | Description |
|---|---|---|
token |
str
|
Bearer token used for authentication. |
expiresIn |
int
|
Access token's validity in seconds. |
refreshToken |
str
|
Token to refresh the session without login. |
refreshExpiresIn |
int
|
Validity of the refresh token in seconds. |
EnrollWithAadhaarResponse ¶
Bases: BaseModel
Response received after a successful ABHA enrollment using Aadhaar.
Combines the profile, authentication tokens, and other enrollment metadata.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
str
|
Server message regarding the result of the enrollment. |
txnId |
str
|
Transaction ID for the enrollment operation. |
ABHAProfile |
AbhaProfile
|
Detailed user profile. |
tokens |
AbhaTokens
|
Authentication tokens for future API access. |
isNew |
bool
|
Indicates whether a new ABHA account was created. |
AbhaAddressSuggestionsResponse ¶
Bases: BaseModel
Response containing suggested available ABHA addresses (PHRs) for the user.
These addresses are generated based on the user’s details and availability.
Attributes:
| Name | Type | Description |
|---|---|---|
abhaAddressList |
list[str]
|
Suggested unique ABHA addresses. |
txnId |
str
|
Transaction ID for this operation. |
CreateAbhaAddressRequest ¶
Bases: BaseModel
Request to create a new ABHA address (PHR) from one of the available suggestions.
Attributes:
| Name | Type | Description |
|---|---|---|
abhaAddress |
str
|
Desired ABHA address selected by the user. |
txnId |
str
|
Transaction ID from the address suggestion step. |
CreateAbhaAddressResponse ¶
Bases: BaseModel
Response after successfully creating a new ABHA address.
Attributes:
| Name | Type | Description |
|---|---|---|
txnId |
str
|
Transaction ID for the creation. |
healthIdNumber |
str
|
Newly created ABHA number. |
preferredAbhaAddress |
str
|
Final chosen and active ABHA address. |
UpdateMobileNumberRequest ¶
Bases: BaseModel
Request to initiate the mobile number update process for a user’s ABHA profile.
The backend will send an OTP to the new number for verification.
Attributes:
| Name | Type | Description |
|---|---|---|
updateValue |
str
|
New mobile number to be registered. |
txnId |
str
|
Transaction ID of the session for traceability. |
VerifyMobileOtpRequest ¶
Bases: BaseModel
Request payload to verify OTP sent to the new mobile number during mobile update.
Attributes:
| Name | Type | Description |
|---|---|---|
otp |
str
|
OTP received on the new mobile number. |
txnId |
str
|
Transaction ID used for the update session. |
VerifyMobileOtpResponse ¶
Bases: BaseModel
Final response confirming the mobile number update after OTP verification.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
str
|
Server status message. |
txnId |
str
|
Transaction ID of the verification session. |
authResult |
str
|
Result of authentication and mobile update. |
ABHAService ¶
ABHAService(config: ClientConfig)
Bases: BaseService
High-level service for managing ABHA (Ayushman Bharat Health Account) creation and verification workflows.
Key Features
- Securely handles all ABHA account creation and verification steps.
- Encrypts sensitive data (Aadhaar, OTP, mobile) using a public key from the environment.
- Robust error handling and logging for all ABHA-related operations.
- Designed for easy SDK and application integration.
Methods:
| Name | Description |
|---|---|
generate_aadhaar_otp |
Initiates the ABHA creation flow by generating an OTP for Aadhaar verification. |
enroll_with_aadhaar |
Completes ABHA enrollment using the OTP received on the Aadhaar-linked mobile number. |
generate_mobile_otp |
Generates an OTP for mobile number verification or update. |
verify_mobile_otp |
Verifies the OTP sent to the user's mobile number for ABHA workflows. |
abha_address_suggestion |
Fetches a list of available ABHA address (username) suggestions for the user. |
create_abha_address |
Registers the chosen ABHA address, finalizing the ABHA creation process. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
ClientConfig
|
API credentials and settings for service initialization. |
required |
Raises:
| Type | Description |
|---|---|
EhrApiError
|
For validation, API, or unexpected errors during operations. |
Example usage
config = ClientConfig(
api_key="your_api_key",
)
service = ABHAService(config)
otp_resp = await service.generate_aadhaar_otp(GenerateAadhaarOtpRequest(aadhaar="xxxx"))
enroll_resp = await service.enroll_with_aadhaar(EnrollWithAadhaar(...))
generate_aadhaar_otp
async
¶
generate_aadhaar_otp(request_body: GenerateAadhaarOtpRequest) -> VerifyOtpResponse
Initiates Aadhaar-based OTP generation.
This method securely encrypts the Aadhaar number using the ABHA public key and requests the ABHA service to generate and send an OTP to the user's Aadhaar-linked mobile. The response includes a transaction ID (txnId) required for the next step of the ABHA enrollment process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request_body
|
GenerateAadhaarOtpRequest
|
User's 12-digit Aadhaar number (unmasked). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
VerifyOtpResponse |
VerifyOtpResponse
|
|
Raises:
| Type | Description |
|---|---|
EhrApiError
|
If Aadhaar is invalid, encryption fails, network/API issues, or OTP dispatch fails. |
Example
req = GenerateAadhaarOtpRequest(aadhaar="123412341234")
resp = await abha_service.generate_aadhaar_otp(req)
print(resp.txnId, resp.message)
Response:¶
Sample Output :
{
"txnId": "3b440ecf-6cd5-4059-9fdd-12e4c14b931a",
"message": "OTP sent successfully to your Aadhaar-linked mobile"
}
enroll_with_aadhaar
async
¶
enroll_with_aadhaar(request_body: EnrollWithAadhaar) -> EnrollWithAadhaarResponse
Completes ABHA enrollment using Aadhaar OTP.
Encrypts the OTP received on the Aadhaar-linked mobile and submits it with the transaction ID and user's mobile number. This finalizes ABHA onboarding, returning a profile, tokens, and session info. Use after successfully verifying the OTP.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request_body
|
EnrollWithAadhaar
|
User's OTP, transaction ID, and mobile number. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
EnrollWithAadhaarResponse |
EnrollWithAadhaarResponse
|
|
Raises:
| Type | Description |
|---|---|
EhrApiError
|
On OTP errors (expired/invalid), encryption failure, or network/server issues. |
Example
req = EnrollWithAadhaar(otp="123456", txnId="d309dc12...", mobile="9123456789")
resp = await abha_service.enroll_with_aadhaar(req)
print(resp.ABHAProfile.firstName, resp.isNew)
Response:¶
Sample Output:
{
"message": "ABHA enrollment successful.",
"txnId": "d309dc12-3cf6-4127-9bd9-8d184d8eb45b",
"ABHAProfile": {
"firstName": "Asha",
"lastName": "Verma",
"mobile": "9123456789",
"...": "..."
},
"tokens": {
"token": "eyJhbGc...",
"expiresIn": 1800,
"refreshToken": "dGhpcy...",
"refreshExpiresIn": 86400
},
"isNew": true
}
generate_mobile_otp
async
¶
generate_mobile_otp(request_body: UpdateMobileNumberRequest) -> VerifyOtpResponse
Initiates mobile OTP generation for verification or update.
Securely encrypts the provided mobile number and requests the ABHA service to generate/send an OTP for that number. Useful for onboarding, mobile update, or mobile verification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request_body
|
UpdateMobileNumberRequest
|
User's new mobile number (unmasked). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
VerifyOtpResponse |
VerifyOtpResponse
|
|
Raises:
| Type | Description |
|---|---|
EhrApiError
|
For invalid numbers, encryption failure, or network/server/dispatch errors. |
Example
req = UpdateMobileNumberRequest(updateValue="9123456789", txnId="txn2456")
resp = await abha_service.generate_mobile_otp(req)
print(resp.txnId, resp.message)
Response:¶
Sample Output:
{
"txnId": "f4b7057c-8374-46df-ad65-c6a18aa6a326",
"message": "OTP sent to the new mobile number."
}
verify_mobile_otp
async
¶
verify_mobile_otp(request_body: VerifyMobileOtpRequest) -> VerifyMobileOtpResponse
Verifies the OTP sent to the user's mobile.
Securely encrypts and submits the OTP received by the user to the ABHA service, completing mobile verification or update.
Use after generate_mobile_otp.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request_body
|
VerifyMobileOtpRequest
|
User's OTP and transaction ID. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
VerifyMobileOtpResponse |
VerifyMobileOtpResponse
|
|
Raises:
| Type | Description |
|---|---|
EhrApiError
|
On OTP invalid/expired/failure, encryption issues, server errors. |
Example
req = VerifyMobileOtpRequest(otp="456789", txnId="txn6677")
resp = await abha_service.verify_mobile_otp(req)
print(resp.message, resp.authResult)
Response:¶
Sample Output :
{
"message": "Mobile verified and updated successfully.",
"txnId": "a1e4b8e7-bc7f-4cc3-ac8b-03b4d4826e86",
"authResult": "VERIFIED"
}
abha_address_suggestion
async
¶
abha_address_suggestion(txnId: str) -> AbhaAddressSuggestionsResponse
Provides a list of available ABHA address (username) suggestions.
Fetches unique, available PHR address (username) suggestions for the user for the current session, aiding user choice for ABHA registration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
txnId
|
str
|
Transaction ID obtained from a previous successful OTP/auth step. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
AbhaAddressSuggestionsResponse |
AbhaAddressSuggestionsResponse
|
|
Raises:
| Type | Description |
|---|---|
EhrApiError
|
If session invalid/expired or on server/network issues. |
Example
resp = await abha_service.abha_address_suggestion(txnId="txn1234")
print(resp.abhaAddressList)
Response:¶
Sample Output :
{
"abhaAddressList": [
"ashaverma.abdm@sbx",
"ashaverma1.abdm@sbx",
"ashaverma1978.abdm@sbx"
],
"txnId": "txn1234"
}
create_abha_address
async
¶
create_abha_address(request_body: CreateAbhaAddressRequest) -> CreateAbhaAddressResponse
Registers and activates a user's chosen ABHA address.
Registers the specified ABHA address (selected from suggestions) for the user with the ABHA system, assigning a unique ABHA number. Use only addresses suggested as available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request_body
|
CreateAbhaAddressRequest
|
User's chosen ABHA address and transaction ID. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
CreateAbhaAddressResponse |
CreateAbhaAddressResponse
|
|
Raises:
| Type | Description |
|---|---|
EhrApiError
|
If chosen address is unavailable, registration fails, session expired, or server issues. |
Example
req = CreateAbhaAddressRequest(abhaAddress="ashaverma1978.abdm@sbx", txnId="txn6789")
resp = await abha_service.create_abha_address(req)
print(resp.healthIdNumber, resp.preferredAbhaAddress)
Response:¶
Sample Output :
{
"txnId": "2ab3d0a7-fb55-4627-9dff-ef780ead3e8f",
"healthIdNumber": "1234-5678-9012",
"preferredAbhaAddress": "ashaverma1978.abdm@sbx"
}
CreateABHA ¶
CreateABHA(config: ClientConfig)
Orchestrated ABHA (Ayushman Bharat Health Account) Registration Workflow
The CreateABHA class provides an end-to-end, asynchronous workflow manager for the multi-step creation
of an ABHA ID under India's National Digital Health Mission (NDHM).
Key Features
- This class abstracts away the low-level calls to individual APIs by sequencing the steps involved.
- Initiating Aadhaar-based OTP (One-Time Password) for user identity validation.
- Completing Aadhaar OTP / mobile verification and linking user’s phone.
- Generating and verifying mobile OTP as required.
- Retrieving and confirming an ABHA address (user’s health account “username”).
- Completing the registration process and collecting final ABHA credentials.
All steps return clear next-step instructions and payload hints so you can drive both back-end workflows and complex UI wizards easily.
Typical user journey
- Step 1: Call
start_registrationwith an Aadhaar number. - Steps 2+: Pass the recommended next step and collected fields to
registration_flow. - Process the returned "next_step" and "next_step_payload_hint" at each stage to guide the next user input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
ClientConfig
|
Configuration object for the ABHA service client. |
required |
Methods:
| Name | Description |
|---|---|
start_registration |
Initiates the ABHA registration process by generating an OTP for the provided Aadhaar number. |
registration_flow |
Advances the ABHA registration workflow by executing a specific step with the required data. |
Returns:
| Type | Description |
|---|---|
|
response[dict]: A dictionary containing the next step and its payload hint. |
Raises:
| Type | Description |
|---|---|
(EhrApiError, ValidationError)
|
On service or data validation failures. |
Exception
|
For business logic errors or workflow step violations. |
Example Usage
config = ClientConfig(
api_base_url="https://api.example.com",
api_key="your_api_key",
api_secret="your_api_secret"
)
abha_creator = CreateABHA(config)
# Step 1: Aadhaar OTP
step1 = await abha_creator.start_registration("123412341234")
# Step 2: Enroll with Aadhaar OTP
step2 = await abha_creator.registration_flow(
AbhaSteps.ENROLL_WITH_AADHAAR,
{"otp": "123456", "txnId": step1["data"]["txnId"], "mobile": "9123456780"}
)
# Follow step2["next_step"] for further steps as guided
start_registration
async
¶
start_registration(aadhaar_number: str) -> dict
Initiates Aadhaar-based OTP flow to begin ABHA registration.
Description:¶
- Securely encrypts the provided Aadhaar number.
- Requests the ABHA service to send an OTP to the mobile number linked with Aadhaar.
- The returned transaction ID (txnId) is essential for verifying OTP and continuing the workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aadhaar_number
|
str
|
12-digit Aadhaar number (as a string, numbers only). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
|
Raises:
| Type | Description |
|---|---|
Exception
|
For encryption, networking, or service errors (with context in logs). |
Example
result = await abha_creator.start_registration("123412341234")
# Use result["data"]["txnId"] for the next step
Response:¶
Sample Output:
-----------
{
"message": "Aadhaar OTP generated. Please enroll with aadhaar by passing transactionId in next step",
"data": {
"txnId": "3b440ecf-6cd5-4059-9fdd-12e4c14b931a",
"message": "OTP sent successfully to your Aadhaar-linked mobile"
},
"next_step": "ENROLL_WITH_AADHAAR",
"next_step_payload_hint": {
"description": "Provide the OTP received via SMS and the transaction ID.",
"required_fields": ["otp", "txnId"],
"source_of_data": {"txnId": "from current step's data.txnId"}
}
}
registration_flow
async
¶
registration_flow(step: AbhaSteps, payload: dict) -> dict
Advance the ABHA registration workflow by executing a specific registration step.
This method allows you to move through the sequential steps needed to create an ABHA ID, including enrollment with Aadhaar OTP, mobile OTP generation/verification, address suggestions, and final address creation.
You pass in the current step and the required data for that step. The method executes the step, returns the result, and provides guidance for the next step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
AbhaSteps
|
The current ABHA registration step to execute. Possible values: - ENROLL_WITH_AADHAAR - GENERATE_MOBILE_OTP - VERIFY_MOBILE_OTP - ABHA_ADDRESS_SUGGESTION - CREATE_ABHA_ADDRESS |
required |
payload
|
dict
|
Required data fields for the step: - ENROLL_WITH_AADHAAR: {'otp', 'txnId', 'mobile'} - GENERATE_MOBILE_OTP: {'updateValue', 'txnId'} # updateValue = mobile number - VERIFY_MOBILE_OTP: {'otp', 'txnId'} - ABHA_ADDRESS_SUGGESTION: {'txnId'} - CREATE_ABHA_ADDRESS: {'abhaAddress', 'txnId'} |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Contains the following keys: - 'message' (str): status message. - 'data' (dict): Response data from the ABHA API for the current step. - 'next_step' (str or None): Next step in the flow, or None if registration is complete. - 'next_step_payload_hint' (dict or None): Specifies what fields are needed for the next step. |
Raises:
| Type | Description |
|---|---|
(EhrApiError, ValidationError)
|
If API returns an error or validation fails. |
Exception
|
For invalid steps or unexpected errors. |
Example usage
# After obtaining txnId from start_registration:
result = await abha_creator.registration_flow(
AbhaSteps.ENROLL_WITH_AADHAAR,
{'otp': '123456', 'txnId': '<txnId>', 'mobile': '9876543210'}
)
print(result['message'])
if result['next_step']:
print(f"Next step: {result['next_step']}")
print(f"Payload needed: {result['next_step_payload_hint']}")
Example output when mobile is already verified (EnrollWithAadhaarResponse):¶
{
"message": "Aadhaar OTP verified. Mobile already verified. Proceed to address suggestion.",
"data": {
"message": "Enrollment successful",
"txnId": "d309dc12-3cf6-4127-9bd9-8d184d8eb45b",
"ABHAProfile": {
"preferredAddress": "ashaverma.abdm@sbx",
"firstName": "Asha",
"lastName": "Verma",
"middleName": "K",
"dob": "1980-07-15",
"gender": "F",
"profilePhoto": null,
"mobile": "9123456789",
...
"yearOfBirth": "1980"
},
"tokens": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"expiresIn": 3600,
"refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9_refresh...",
"refreshExpiresIn": 86400
},
"isNew": true
},
"next_step": "ABHA_ADDRESS_SUGGESTION",
"next_step_payload_hint": {
"description": "Provide 'txnId' from this step's data for address suggestion.",
"required_fields": ["txnId"],
"source_of_data": {"txnId": "from current step's data.txnId"}
}
}
Example output when mobile OTP verification is needed (after GENERATE_MOBILE_OTP and VERIFY_MOBILE_OTP steps):¶
{
"message": "Mobile OTP verified.",
"data": {
"message": "Mobile verified successfully",
"txnId": "a1e4b8e7-bc7f-4cc3-ac8b-03b4d4826e86",
"authResult": "VERIFIED"
},
"next_step": "ABHA_ADDRESS_SUGGESTION",
"next_step_payload_hint": {
"description": "Provide 'txnId' to fetch address suggestions.",
"required_fields": ["txnId"],
"source_of_data": {"txnId": "from current step's data.txnId"}
}
}
Example output of ABHA address suggestions (AbhaAddressSuggestionsResponse):¶
{
"message": "ABHA ID suggestions retrieved. Proceed to create the ABHA ID.",
"data": {
"abhaAddressList": [
"ashaverma.abdm@sbx",
"ashaverma1.abdm@sbx",
"ashaverma1978.abdm@sbx"
],
"txnId": "txn1234"
},
"next_step": "CREATE_ABHA_ADDRESS",
"next_step_payload_hint": {
"description": "Choose one abhaAddress and provide it with txnId for registration.",
"required_fields": ["abhaAddress", "txnId"],
"source_of_data": {
"abhaAddress": "from data.abhaAddressList above",
"txnId": "from previous step"
}
}
}
Example output of final creation success (CreateAbhaAddressResponse):¶
{
"message": "ABHA ID created successfully. Registration complete.",
"data": {
"txnId": "2ab3d0a7-fb55-4627-9dff-ef780ead3e8f",
"healthIdNumber": "1234-5678-9012",
"preferredAbhaAddress": "ashaverma1978.abdm@sbx"
},
"next_step": null
}
EncryptData ¶
EncryptData()
Utility class for encrypting sensitive data using RSA-OAEP with SHA-1. This class is designed to securely encrypt identifiers such as Aadhaar numbers, OTPs, or mobile numbers before transmitting them to the ABHA (Ayushman Bharat Health Account) APIs. Key Features: - Encrypts data using RSA public keys. - Supports both PEM-formatted public keys and base64-encoded key strings. - Returns the encrypted data as a base64-encoded string. Example usage: encrypted = await encrypt_data_for_abha("123456789012", public_key_pem)
encrypt_data_for_abha
async
¶
encrypt_data_for_abha(data_to_encrypt: str, certificate_pem: str) -> str
Encrypt sensitive data using RSA-OAEP with SHA-1 and a provided public key.
This utility is designed for securely encrypting identifiers such as Aadhaar numbers, OTPs, or mobile numbers before transmitting them to the ABHA (Ayushman Bharat Health Account) APIs. The function accepts either a full PEM-formatted public key or a base64-encoded key string, ensuring compatibility with various key formats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_to_encrypt
|
str
|
The plaintext data to be encrypted (e.g., Aadhaar number, OTP). |
required |
certificate_pem
|
str
|
The public key in PEM format or as a base64-encoded string. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The base64-encoded ciphertext, ready for secure transmission to the ABHA API. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the provided public key is invalid or encryption fails. |
Example usage
encrypted = await encrypt_data_for_abha("123456789012", public_key_pem)