Add Unit Tests and improve generateSecretKey