In the most general sense, "signing" in this context means a process that depends on the text and some secret knowledge in such a way that anyone with access to the text and secret knowledge can create the output, and anyone given the text and the output can verify that the output is correct, but it is infeasible for anyone who doesn't have access to the secret knowledge to independently produce the correct output.
One method of doing this is using public key encryption, which is a system in which there are two keys and a cryptographic process such that applying the cryptographic process with one key, then taking the result and applying the cryptographic process with the other key, results in the original input. One of these keys is publicly distributed, and known as the "public key", and the other key is kept secret, and is known as the "private key".
When used to restrict access to information, which is what “encryption” generally refers to, public key encryption consists of the sender using the recipient’s public key on the file, and the recipient uses their private key on their result; thus, only the intended recipient can read the file. Signing can be accomplished by having the sender use their private key, and the recipient using the sender’s public key. Thus, while in the first case only the recipient can read the file (since only they have their private key), in the second case only the sender can send the file (since only they know their private key). In the first case, everyone can write, but only one can read, while in the second case, only one person can write but everyone can read.
If just the result from using the sender’s private key is sent, then everyone will have to get the sender’s public key to read the file. So often the original file is sent as well, so that people can read it without going through that process. But since sending both the file and the result of applying the cryptographic process to the whole file means sending twice as much data as just the file, a hash is usually used to decrease the size of the signature. This can be done by hashing the file and then signing the hash (and then the recipient can hash the file and apply the cryptographic process with the public key to the hashed file, and see if that matches the signed hash that was sent).
Although signing a file, verifying a signature, and encryption can all use the same cryptographic process, the term "encryption" is primarily used refer specifically to when this process is used to keep other people from reading the file, rather than for authentication. If we're applying the process for secrecy, then we send only the result, as we don't want unauthorized people to have access to the plaintext. If we're authenticating, we send both so that the recipient can check that they match.
If a sender wants only the intended recipient to be able to read a file, then the sender can encrypt as a separate process. So how that would work is that the sender would hash the file, apply their private key to the result, append that result to the file, then apply the recipient's private key to the file+signature, and then send that to the recipient. Thus, the recipient would get message=recipient.public(file+sender.private(hash(file))
. The recipient would then apply their private key to the message, hash the original file part of the result, and check whether that matches the sender's public key applied to the signature:
hash((recipient.private(message)).file) == sender.public((recipient.private(message)).signature)