@@ -61,7 +61,7 @@ export class VirgilCrypto {
6161
6262 generateKeysFromKeyMaterial ( keyMaterial : Data , type ?: KeyPairTypeType [ keyof KeyPairTypeType ] ) {
6363 const keyPairType = type ? type : this . defaultKeyPairType ;
64- const myKeyMaterial = dataToUint8Array ( keyMaterial ) ;
64+ const myKeyMaterial = dataToUint8Array ( keyMaterial , 'base64' ) ;
6565
6666 const keyMaterialRng = new this . foundationModules . KeyMaterialRng ( ) ;
6767 keyMaterialRng . resetKeyMaterial ( myKeyMaterial ) ;
@@ -85,7 +85,7 @@ export class VirgilCrypto {
8585 }
8686
8787 importPrivateKey ( rawPrivateKey : Data ) {
88- const myRawPrivateKey = dataToUint8Array ( rawPrivateKey ) ;
88+ const myRawPrivateKey = dataToUint8Array ( rawPrivateKey , 'base64' ) ;
8989
9090 const keyProvider = new this . foundationModules . KeyProvider ( ) ;
9191 keyProvider . setupDefaults ( ) ;
@@ -128,7 +128,7 @@ export class VirgilCrypto {
128128 }
129129
130130 importPublicKey ( rawPublicKey : Data ) {
131- const myRawPublicKey = dataToUint8Array ( rawPublicKey ) ;
131+ const myRawPublicKey = dataToUint8Array ( rawPublicKey , 'base64' ) ;
132132
133133 const keyProvider = new this . foundationModules . KeyProvider ( ) ;
134134 keyProvider . setupDefaults ( ) ;
@@ -162,7 +162,7 @@ export class VirgilCrypto {
162162 }
163163
164164 encrypt ( data : Data , publicKey : VirgilPublicKey | VirgilPublicKey [ ] ) {
165- const myData = dataToUint8Array ( data ) ;
165+ const myData = dataToUint8Array ( data , 'utf8' ) ;
166166 const publicKeys = toArray ( publicKey ) ;
167167 validatePublicKeysArray ( publicKeys ) ;
168168
@@ -189,11 +189,12 @@ export class VirgilCrypto {
189189 }
190190
191191 decrypt ( encryptedData : Data , privateKey : VirgilPrivateKey ) {
192- const myData = dataToUint8Array ( encryptedData ) ;
192+ const myData = dataToUint8Array ( encryptedData , 'base64' ) ;
193193 validatePrivateKey ( privateKey ) ;
194194 const lowLevelPrivateKey = getLowLevelPrivateKey ( privateKey ) ;
195195
196196 const recipientCipher = new this . foundationModules . RecipientCipher ( ) ;
197+ recipientCipher . random = this . random ;
197198
198199 recipientCipher . startDecryptionWithKey (
199200 privateKey . identifier ,
@@ -214,7 +215,7 @@ export class VirgilCrypto {
214215 data : Data ,
215216 algorithm : HashAlgorithmType [ keyof HashAlgorithmType ] = HashAlgorithm . SHA512 ,
216217 ) {
217- const myData = dataToUint8Array ( data ) ;
218+ const myData = dataToUint8Array ( data , 'utf8' ) ;
218219 let result : Uint8Array ;
219220 switch ( algorithm ) {
220221 case HashAlgorithm . SHA224 :
@@ -243,7 +244,7 @@ export class VirgilCrypto {
243244 }
244245
245246 calculateSignature ( data : Data , privateKey : VirgilPrivateKey ) {
246- const myData = dataToUint8Array ( data ) ;
247+ const myData = dataToUint8Array ( data , 'utf8' ) ;
247248 validatePrivateKey ( privateKey ) ;
248249 const lowLevelPrivateKey = getLowLevelPrivateKey ( privateKey ) ;
249250
@@ -264,8 +265,8 @@ export class VirgilCrypto {
264265 }
265266
266267 verifySignature ( data : Data , signature : Data , publicKey : VirgilPublicKey ) {
267- const myData = dataToUint8Array ( data ) ;
268- const mySignature = dataToUint8Array ( signature ) ;
268+ const myData = dataToUint8Array ( data , 'utf8' ) ;
269+ const mySignature = dataToUint8Array ( signature , 'base64' ) ;
269270 validatePublicKey ( publicKey ) ;
270271
271272 const verifier = new this . foundationModules . Verifier ( ) ;
@@ -284,7 +285,7 @@ export class VirgilCrypto {
284285 privateKey : VirgilPrivateKey ,
285286 publicKey : VirgilPublicKey | VirgilPublicKey [ ] ,
286287 ) {
287- const myData = dataToUint8Array ( data ) ;
288+ const myData = dataToUint8Array ( data , 'utf8' ) ;
288289
289290 validatePrivateKey ( privateKey ) ;
290291
@@ -324,7 +325,7 @@ export class VirgilCrypto {
324325 privateKey : VirgilPrivateKey ,
325326 publicKey : VirgilPublicKey | VirgilPublicKey [ ] ,
326327 ) {
327- const myEncryptedData = dataToUint8Array ( encryptedData ) ;
328+ const myEncryptedData = dataToUint8Array ( encryptedData , 'base64' ) ;
328329
329330 const publicKeys = toArray ( publicKey ) ;
330331 validatePublicKeysArray ( publicKeys ) ;
@@ -333,6 +334,7 @@ export class VirgilCrypto {
333334 const lowLevelPrivateKey = getLowLevelPrivateKey ( privateKey ) ;
334335
335336 const recipientCipher = new this . foundationModules . RecipientCipher ( ) ;
337+ recipientCipher . random = this . random ;
336338
337339 recipientCipher . startDecryptionWithKey (
338340 privateKey . identifier ,
@@ -386,7 +388,7 @@ export class VirgilCrypto {
386388 privateKey : VirgilPrivateKey ,
387389 publicKey : VirgilPublicKey | VirgilPublicKey [ ] ,
388390 ) {
389- const myData = dataToUint8Array ( data ) ;
391+ const myData = dataToUint8Array ( data , 'utf8' ) ;
390392
391393 validatePrivateKey ( privateKey ) ;
392394
@@ -430,8 +432,8 @@ export class VirgilCrypto {
430432 privateKey : VirgilPrivateKey ,
431433 publicKey : VirgilPublicKey | VirgilPublicKey [ ] ,
432434 ) {
433- const myEncryptedData = dataToUint8Array ( encryptedData ) ;
434- const myMetadata = dataToUint8Array ( metadata ) ;
435+ const myEncryptedData = dataToUint8Array ( encryptedData , 'base64' ) ;
436+ const myMetadata = dataToUint8Array ( metadata , 'base64' ) ;
435437
436438 validatePrivateKey ( privateKey ) ;
437439 const lowLevelPrivateKey = getLowLevelPrivateKey ( privateKey ) ;
@@ -440,6 +442,7 @@ export class VirgilCrypto {
440442 validatePublicKeysArray ( publicKeys ) ;
441443
442444 const recipientCipher = new this . foundationModules . RecipientCipher ( ) ;
445+ recipientCipher . random = this . random ;
443446
444447 recipientCipher . startDecryptionWithKey ( privateKey . identifier , lowLevelPrivateKey , myMetadata ) ;
445448 const processDecryption = recipientCipher . processDecryption ( myEncryptedData ) ;
0 commit comments