(encryptedValue: string)
| 40 | * text and returned unchanged. |
| 41 | */ |
| 42 | export async function decryptApiKey(encryptedValue: string): Promise<{ decrypted: string }> { |
| 43 | const parts = encryptedValue.split(':') |
| 44 | if (parts.length !== 3) { |
| 45 | return { decrypted: encryptedValue } |
| 46 | } |
| 47 | |
| 48 | const key = getApiEncryptionKey() |
| 49 | if (!key) { |
| 50 | return { decrypted: encryptedValue } |
| 51 | } |
| 52 | |
| 53 | try { |
| 54 | return await decrypt(encryptedValue, key) |
| 55 | } catch (error) { |
| 56 | logger.error('API key decryption error:', { error: toError(error).message }) |
| 57 | throw error |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Generates a standardized API key with the 'sim_' prefix (legacy format) |
no test coverage detected