Invalid parameter in encrypt (JavaScript, UWP)

0

I would like to encrypt data in UWP appliaction writen in javascript.

var publicKey = Windows.Security.Cryptography.Core.PersistedKeyProvider.openPublicKeyFromCertificate(cert, "", Windows.Security.Cryptography.Core.CryptographicPadding.none);
var buffer = Windows.Security.Cryptography.CryptographicBuffer.createFromByteArray(bytes);
var iv = null;
var encrypted = Windows.Security.Cryptography.Core.CryptographicEngine.encrypt(publicKey, buffer, iv);

But I get exception on the last line: 0x80090027 - JavaScript runtime error: Parametr není správný. (Invalid parameter)

But which parameter?

Certificate is created by command

New-SelfSignedCertificate -Type Custom -Subject "test" -KeyAlgorithm RSA -KeyLength 2048 -CertStoreLocation "Cert:\CurrentUser\My"

and obtained by Windows.Security.Cryptography.Certificates.CertificateStores.

javascript
uwp
cryptography
asked on Stack Overflow Jun 28, 2018 by user3706629

1 Answer

0

When RSA is used, buffer must have some defined size. If it is smaller exception (Invalid parameter - without any details) is raised. When padding is changed from CryptographicPadding.none to CryptographicPadding.rsaPkcs1V15 encrypting works.

answered on Stack Overflow Jun 29, 2018 by user3706629

User contributions licensed under CC BY-SA 3.0