(stringToDecrypt: string)
| 44 | |
| 45 | // Decrypt token using the inverse of encryption crypto algorithm |
| 46 | export const decryptToken = (stringToDecrypt: string): string | undefined => { |
| 47 | try { |
| 48 | const key = crypto.createHash('sha256').update(getTokenHashSecret()).digest() |
| 49 | |
| 50 | let textParts = stringToDecrypt.split(':') |
| 51 | let iv = Buffer.from(textParts.shift() as string, 'hex') |
| 52 | let encryptedText = Buffer.from(textParts.join(':'), 'hex') |
| 53 | let decipher = crypto.createDecipheriv('aes-256-cbc', key, iv) |
| 54 | let decrypted = decipher.update(encryptedText) |
| 55 | |
| 56 | const result = Buffer.concat([decrypted, decipher.final()]) |
| 57 | |
| 58 | return result.toString() |
| 59 | } catch (error) { |
| 60 | return undefined |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | // Extract userUUID from decrypted token string |
| 65 | export const getUserUUIDFromToken = (token: string): string | undefined => { |
no test coverage detected