private String decryptResponse(ResponseInfo objResponseInfo) { byte[] signature = Convert.FromBase64String(objResponseInfo.Signature); string hash = Convert.ToBase64String(m_encryptorVerifier.decrypt(signature)); byte[] encryptedResponseString = Convert.FromBase64String(objResponseInfo.Response); string expectedHash = Convert.ToBase64String(Hash.getHash(encryptedResponseString)); if (!hash.Equals(expectedHash)) { throw new InvalidSignatureException(); } byte[] key = m_signerDecryptor.decrypt(Convert.FromBase64String(objResponseInfo.Key)); byte[] iv = m_signerDecryptor.decrypt(Convert.FromBase64String(objResponseInfo.IV)); AESCipher cipher = new AESCipher(key, iv); return(cipher.decrypt(encryptedResponseString)); }
private String encryptResponse(String response) { // Generate a key for encrypting the response m_aesCipher.GenerateNewKeyAndIV(); // Encrypt the response byte[] encryptedResponse = m_aesCipher.encrypt(response); // Encrypt the AES key and IV String encryptedAESKey = Convert.ToBase64String(m_encryptorVerifier .encrypt(m_aesCipher.Key)); String encryptedIV = Convert.ToBase64String(m_encryptorVerifier .encrypt(m_aesCipher.IV)); // Hash the encrypted method // Sign the hash (encrypt it with the signer) byte[] signedHash = m_signerDecryptor.encrypt(Hash .getHash(encryptedResponse)); ResponseInfo objResponseInfo = new ResponseInfo(encryptedAESKey, encryptedIV, Convert.ToBase64String(encryptedResponse), Convert.ToBase64String(signedHash)); return(objResponseInfo.encode()); }