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.
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.
User contributions licensed under CC BY-SA 3.0