1

I am trying to encrypt loginDTO to base64 with a key in angular 5 application . I know we have blot() which accepts a string and converts to base64 but not sure how to do it here.

Const credential = 
  { username : 'abc123' 
    password : '12345'
  };

 Const Key = 'some key' 

Could someone help me to convert this object to byte array and then encrypt to base64 with key.

Note- I cannot use any external library like cryptoJS Since the same encryption method is written for mobile app in xamarin and backend is same for web and mobile c#.

georgeawg
  • 48,608
  • 13
  • 72
  • 95
user2282534
  • 39
  • 2
  • 8
  • Base64 is not for 'encoding with a key'. It is simply a encoding scheme. Have you tried: btoa(JSON.stringify(credential)) ? Note: You will need a symmetric encryption algorithm like AES (for example) to encrypt the output of the stringify with a key. – GabrielBiga Jan 11 '20 at 02:57

2 Answers2

2

Base64 is simple encoding scheme, it is not for 'encoding with a key'. you can use Base64 to encrypt and decrypt strings without any extra key.

Ref : https://stackoverflow.com/a/6348344/9009397

Ref : https://en.wikipedia.org/wiki/Base64

You can use another encoding method that support encryption with key

Ex: 'crypto-js' http://github.com/brix/crypto-js

https://stackoverflow.com/a/53478984/10430605

0

We must clearly distinguish between "encrypting" and "encoding".

Encrypting uses an encryption key to convert data in a way that it cannot be made readable again (= decrypted) without the appropriate decryption key.

Encoding, however, means to change the representation scheme of data. As a common example, a text can be encoded in ASCII or UTF-8, and it can be converted from one encoding to another by anyone.

Base64 is an encoding scheme. For your purposes, you need encryption.

not2savvy
  • 2,902
  • 3
  • 22
  • 37