Refactor getEncryptionKey method