Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local API payment request with encryption generates key on every Encrypt #1084

Open
mvdzwaan opened this issue Nov 14, 2024 · 2 comments
Open

Comments

@mvdzwaan
Copy link

When using the TerminalApiLocalService.RequestEncryptedAsync the current library generates the needed encrypt keys for each request.

Looking at the EncryptionDerivedKeyGenerator.Generate method, this methods creates the same key on each call, while still performing a Rfc2898DeriveBytes with 4000 iterations.

Could we improve performance of all calls by using a static key which only gets created once ?

Performance is not much of an issue when starting a payment, but when using VirtualReceipts we would like this call to be as performant as it can be.

@Kwok-he-Chu
Copy link
Contributor

That makes sense

Affected classes:

Since the password is dynamic, we need a way to pass this into the EncryptionCredentialDetails, my suggestion, we could move the var encryptionDerivedKey = _encryptionDerivedKeyGenerator.Generate(encryptionCredentialDetails);-part to the constructor above, what do you think?

@mvdzwaan
Copy link
Author

mvdzwaan commented Feb 3, 2025

I forked and was in the process of creating a pull request using another tactic

https://github.com/Adyen/adyen-dotnet-api-library/compare/main...mvdzwaan:adyen-dotnet-api-library:main

Using a static in the EncryptionDerivedKeyGenerator class.

I think the provided password will not be dynamic, but if it really is, we could store it too and compare before deciding to give the cached key or recalculate it again.

I used my version and it was working fine as is... Performance gains on my desktop were not as big as hoped, but on slower devices it will help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants