@polybase/util
Install Polybase Util
Encrypt data using symmetric encryption
Symmetric encryption is a form of encryption which has only one key. You use the same key to perform both encrypt and decrypt functions. There are a number of different algorithms, but we recommend usingaes-cbc:
Encrypt data using asymmetric encryption
Asymmetric encryption allows you to encrypt with one key (the public key) and decrypt with another key (the private key). The public key can be shared with anyone, as only the private key can be used to decrypt the data. The advantage of this approach, is that you do not have to find a way to securely send a sensitive key from one user to another (as you would with symmetric encryption). There are a number of different algorithms, but we recommend usingsecp256k1 (the algorithm used by Ethereum):
Uint8Array
Most of our encryption utilities returnUint8Array values. Uint8Array is similar to node’s Buffer type, but is
natively compatible with both node and the browser, meaning no complex setup or polyfill is required to use it.
Converting Uint8Array to string
To convert fromstring to Uint8Array:
Uint8Array to string:
Converting Uint8Array to Buffer
To convert fromUint8Array to Buffer:
Buffer to Uint8Array:
Encoding Uint8Array to Hex
To convert fromUint8Array to a hexadecimal encoded string:
hexadecimal encoded string to Uint8Array:
Encoding Uint8Array to Base64
To convert fromUint8Array to a base64 encoded string:
base64 encoded string to Uint8Array: