def initRemoteKeys(name, remoteName, baseDir, verkey, override=False): homeDir = ZStack.homeDirPath(baseDir, name) verifDirPath = ZStack.verifDirPath(homeDir) pubDirPath = ZStack.publicDirPath(homeDir) for d in (homeDir, verifDirPath, pubDirPath): os.makedirs(d, exist_ok=True) if isHex(verkey): verkey = unhexlify(verkey) createCertsFromKeys(verifDirPath, remoteName, z85.encode(verkey)) public_key = ed25519PkToCurve25519(verkey) createCertsFromKeys(pubDirPath, remoteName, z85.encode(public_key))
def getSymmetricallyEncryptedVal(val, secretKey: Union[str, bytes]=None) -> Tuple[str, str]: """ Encrypt the provided value with symmetric encryption :param val: the value to encrypt :param secretKey: Optional key, if provided should be either in hex or bytes :return: Tuple of the encrypted value and secret key encoded in hex """ if isinstance(val, str): val = val.encode("utf-8") if secretKey: if isHex(secretKey): secretKey = bytes(bytearray.fromhex(secretKey)) elif not isinstance(secretKey, bytes): error("Secret key must be either in hex or bytes") box = libnacl.secret.SecretBox(secretKey) else: box = libnacl.secret.SecretBox() return box.encrypt(val).hex(), box.sk.hex()
def getSymmetricallyEncryptedVal( val, secretKey: Union[str, bytes]=None) -> Tuple[str, str]: """ Encrypt the provided value with symmetric encryption :param val: the value to encrypt :param secretKey: Optional key, if provided should be either in hex or bytes :return: Tuple of the encrypted value and secret key encoded in hex """ if isinstance(val, str): val = val.encode("utf-8") if secretKey: if isHex(secretKey): secretKey = bytes(bytearray.fromhex(secretKey)) elif not isinstance(secretKey, bytes): error("Secret key must be either in hex or bytes") box = libnacl.secret.SecretBox(secretKey) else: box = libnacl.secret.SecretBox() return box.encrypt(val).hex(), box.sk.hex()