Implement encryption utilities for securely storing API keys: - encryptApiKey(): encrypts keys using Electron safeStorage with base64 encoding - decryptApiKey(): decrypts stored keys - isEncryptionAvailable(): checks platform support Encryption falls back to plaintext on platforms without keyring support. Includes comprehensive test coverage with Electron mock.
14 lines
387 B
TypeScript
14 lines
387 B
TypeScript
/**
|
|
* Mock Electron API for testing
|
|
* This provides minimal mocks for the Electron types used in tests
|
|
*/
|
|
|
|
export const safeStorage = {
|
|
isEncryptionAvailable: jest.fn(() => true),
|
|
encryptString: jest.fn((data: string) => Buffer.from(`encrypted:${data}`)),
|
|
decryptString: jest.fn((buffer: Buffer) => {
|
|
const str = buffer.toString();
|
|
return str.replace('encrypted:', '');
|
|
})
|
|
};
|