Retrieves an existing P256 key pair if one has been previously generated and stored. This is useful for checking if keys already exist before generating new ones.
Parameters
This function takes no parameters.Returns
P256KeyPair | null
The stored P256 key pair or
null if no key pair exists.Get or Create Pattern
A common pattern is to check for existing keys before generating new ones:Storage Behavior
ThegetKeypair function retrieves keys from:
- Browser’s secure storage (for web applications)
- Platform-specific secure storage (for native applications)
- Memory cache (for the current session)
Key pairs are stored securely and are only accessible within the same origin and application context.
Error Handling
ThegetKeypair function can throw errors for:
- Storage access failures
- Data corruption issues
- Browser compatibility problems
getKeypair in a try-catch block:
Key Lifecycle Management
Security Considerations
- Always verify key integrity before use
- Implement proper access controls
- Consider re-generating keys periodically for enhanced security