c# – Encrypting Data with interception of SQL instructions generated by Entity Framework

WPF Application, C#, MS SQL Server, Entity Framework 6. I need to encrypt all data from user input, and do it apart from business logic. I’ve come to interception of SQL Queries generated by transferring LINQ expressions to SQL, and changing data from them to encrypted, in order to store only encrypted data. I’d like to know if it even possible, and how… And how to decrypt them back and show user only plaintext. I can’t change this method – i.e. i MUST intercept queries. Yet another thing – i must use methods from System.Security.Cryptography.
I have read https://docs.microsoft.com/en-us/ef/ef6/fundamentals/logging-and-interception this article – we use EF version of 4.1, this will not work. I had even checked through source code of EF6 on Github to check if i can override SaveChanges() method

Cryptography: security risk of encrypting the same data with many public keys

I need to distribute a 256-bit shared key to 100 or 1000 nodes (I have the public key of each node).

There are no networks involved: all this will be done by loading a single file on each node. That file is generated by a "teacher."

In some cases, the nodes use 2048-bit RSA keys, and others is a p521 elliptic curve key.

The idea is to create a line for each node in the distributed file that encrypts the shared key.

If the node uses EC, then the public ECs of the node and the private EC keys of the master are used to generate a symmetric key that is used to encrypt the shared key. The encrypted shared key and the signature generated by the master are stored in a line in the file.
The node will then cycle through each line of the file, use the teacher's public EC key and its own private EC key to generate the same symmetric key, decrypt the data and then verify the signature. If it is correct, then that is the shared key.

If the node uses RSA, then the shared key will be encrypted with the node's public RSA key and a signature generated by the master and both stored on a line in the file.
The node will then cycle through each line of the file, use its RSA private key to decrypt the data and then verify the signature. If it is correct, then that is the shared key.

My concern is that knowing that a single piece of data is encrypted with 1000 different keys gives the attacker a significant advantage to obtain a private key.

Would encrypting a password first make slow hashing algorithms unnecessary?

If you first encrypt a password with a secure key and then analyze the result, and both algorithms are fast, say sha_256(salt+aes_256(password, secure_key))Would that make the hash costly for brute force without it being costly to generate?

man in the middle – What are the security concerns about using keepalive TCP without encrypting with TLS?

In my software, both the server and the client send unencrypted TCP alert messages to detect the broken pipe in a reasonable time. It also uses TLS 1.3 encryption with OpenSSL 1.1.1.

Is there any safety concern about this?

For example: the Man-in-the-middle attacker interrupts the communication. To supplant on both sides that the connection is still alive, periodically send / forward TCP keepalives.

Is this scenario possible? It is probable?

What other scenario do you think of?

Cryptography: what happens when encrypting with private key?

The fact that public / private keys are for encryption / signature respectively is not a general fact of public key encryption: it is specific to RSA, where public and private keys have (at least in the textbook) the same form . Switch to systems based on Diffie-Hellman and / or ECC and the two key types look completely different, so you cannot encrypt with a private key.

The short answer to your question is that if Person1 has the private Persona2 key, then something already went wrong and most likely no one gets any security. This type of thing happens all the time (I think github has a special error message for people who paste a private key in the field where an SSH public key is expected to configure authentication with SSH key).

The complete answer: if Person1 uses their own private key, if they are doing a textbook RSA, then anyone with the public key of Person1 can retrieve the message. And public keys are supposed to be public. In the real world, RSA keys and other data structures are removed a few steps from the textbook, and a sensible cryptographic library should not offer the option of encrypting with a private key first. Usually, it would also have separate subkeys for encryption and signature, which would again be stored in different formats (it is a very bad idea to use the same key for both, even if in theory).

In the RSA textbook, it has a public module N, a public exponent e and a private exponent d. In encryption mode, calculate an encrypted text c from a message m such as c = m ^ e (mod N); to decipher compute m = c ^ d (mod N). To sign m, publish s = H (m) ^ d (mod N) and to verify a signature s in m, verify that H (m) = s ^ e (mod N). So public and secret operations are interchangeable. In fact, no matter which one calls e and which one calls d, the two are interchangeable: x ^ e ^ d (mod N) = x ^ d ^ e (mod N) = x (mod N) for all 0 <x <N. (Well, almost everyone, as long as you don't reach a factor of N. In which case, you're roasted anyway.)

sql server: the encrypted stored procedure is encrypting the plan cache query plan

I have a really strange problem checking the plan cache related to encryption of stored procedures. However, it is the stored procedure that is consulting the plan cache that is encrypted, not the queries in the plan cache itself. Let me explain …

The following procedure simply searches the plan cache for a matching string and generates the query plan (the last column).

    ALTER PROCEDURE spQueryPlanCache @textstring nvarchar(max)
    AS
    BEGIN
        SELECT 
                databases.name,
            dm_exec_sql_text.text AS TSQL_Text,
            dm_exec_query_stats.creation_time, 
            dm_exec_query_stats.execution_count,
            dm_exec_query_stats.total_worker_time AS total_cpu_time,
            dm_exec_query_stats.total_elapsed_time, 
            dm_exec_query_stats.total_logical_reads, 
            dm_exec_query_stats.total_physical_reads, 
            dm_exec_query_plan.query_plan
        FROM sys.dm_exec_query_stats 
        CROSS APPLY sys.dm_exec_sql_text(dm_exec_query_stats.plan_handle)
        CROSS APPLY sys.dm_exec_query_plan(dm_exec_query_stats.plan_handle)
        INNER JOIN sys.databases
        ON dm_exec_sql_text.dbid = databases.database_id
        WHERE dm_exec_sql_text.text LIKE @textstring

    END

This is a sample of the XML plan shown in the last column:

   

This makes no sense to me. The only circumstance in which I would expect this to happen is if spMySproc was also encrypted, which is not the case! If I check the plan cache again, I can see that spMySproc is not encrypted.

Is it a known mistake or can someone explain why this makes sense to them?

Thank you

Is it possible to store the National Insurance number and the Unique Taxpayer Reference without encrypting it in a database?

Should this encrypted data, at all or in plain text, be stored in a database?

python – Encrypting files using pynacl

I need a fairly simple file encryptor / decoder in Python; After some research, I decided to use the tye pynacl library to read the file in blocks, rewrite them and then finally use Blake2b to generate a signature for the file. Each file is encrypted with a unique key, which will be distributed together with the encrypted file, with the RSA key encrypted using a pair of previously shared keys, and the entire message signed with ECDSA to verify that it comes from me.

The encryption / decryption example code:

import base64
import structure
import nacl.secret
import nacl.utils
import nacl.hashlib
import nacl.hash

BUFFER_SIZE = 4 * (1024 * 1024)

def read_file_blocks (file, extra_bytes = 0):
while True
data = file.read (BUFFER_SIZE + extra_bytes)
if they are not data:
break
performance data

def hmac_file (file, password):
blake = nacl.hashlib.blake2b (key = key)
with open (file, & # 39; rb & # 39;) as in_file:
for the block in read_file_blocks (in_file):
blake.update (block)
back blake.hexdigest ()

def encrypt_archive (archive_name, encrypted_name):
key = nacl.utils.random (nacl.secret.SecretBox.KEY_SIZE)
#Use 4 bytes less than the nonce size to make room for the block counter
nonce = nacl.utils.random (nacl.secret.SecretBox.NONCE_SIZE - 4)
block_num = 0

box = nacl.secret.SecretBox (key)
with open (archive_name, & # 39; rb & # 39;) as in_file, open (encrypted_name, & # 39; wb & # 39;) as out_file:
for data in read_file_blocks (in_file):
# Apply the block counter to the nonce, so each block has a unique nonce
block_nonce = nonce + struct.pack ("> I", block_num)
block = box.encrypt (data, block_nonce)
out_file.write (block.ciphertext)
block_num + = 1

hmac_key = nacl.hash.sha256 (key + nonce, encoder = nacl.encoding.RawEncoder)
output = {}
exit['key'] = base64.b64encode (key + nonce)
exit['signature'] = hmac_file (encrypted_name, hmac_key)
return output

def decrypt_archive (encrypted_name, archive_name, key_info):
key_bytes = base64.b64decode (key_info['key'])

key = key_bytes[:nacl.secret.SecretBox.KEY_SIZE]
    nonce = key_bytes[nacl.secret.SecretBox.KEY_SIZE:]

    extra_bytes = nacl.secret.SecretBox.MACBYTES
hmac_key = nacl.hash.sha256 (key_bytes, encoder = nacl.encoding.RawEncoder)
hmac = hmac_file (encrypted_name, hmac_key)
if hmac! = key_info['signature']:
print (& # 39; hmac pairing & # 39;)
he came back

block_num = 0
box = nacl.secret.SecretBox (key)
with open (encrypted_name, & # 39; rb & # 39;) as in_file, open (archive_name, & # 39; wb & # 39;) as out_file:
# nacl adds a MAC to each block, when reading the file, this must be taken into account
for data in read_file_blocks (in_file, extra_bytes = extra_bytes):
block_nonce = nonce + struct.pack ("> I", block_num)
block = box.decrypt (data, block_nonce)
out_file.write (block)
block_num + = 1

key_info = encrypt_archive ("C: \ temp \ test.csv", "C: \ temp \ test.enc")
print (key_info)
decrypt_archive ("C: \ temp \ test.enc", "C: \ temp \ test.enc.csv", key_info)

Out of the general mistakes, the two things I'm doing I'm not entirely sure are:

  1. To keep the block nonces unique, I create a random list of bytes a little smaller for the nonce than the required one, then, when I encrypt the blocks, I add the block number, as an integer of four bytes to the nonce.

  2. When generating the blake2b hash, for a key, I click on the key and the nonce of the file. This seems a bit useless in general, because if they have the key and can not replace the file. Although, I really can not think of a better alternative that does not have similar weaknesses. Should I just get rid of that bit, since NaCl does MAC per block anyway? (which I discovered only after writing the hmac code)

Encrypting the Azure SQL database – Swapping database administrators

Currently I have a blue subscription in it has a server and a database.

How can I encrypt a SQL table azure and when the encryption is done I can still insert some data in the table?

I already tried the encryption part, but when I try to insert a data, I received a couple of errors and I can not insert the data.

I'm a rookie when it comes to Azure and as a DBA

Encryption: What are the benefits of a full format compared to a fast format when encrypting an external hard drive?

According to a publication in the Veracrypt forum, it is recommended that the new hard disks be completely formatted. It does not seem to make a distinction between internal and / or external hard drives or USB drives.

Assuming that this is the recommended approach, what are the benefits and / or risks of a full format compared to a fast format?

For example, does a fully formatted hard drive reduce information leakage? If so, how?

The scenario is that no confidential data has been stored in the unit before.

Are there scenarios in which a fast format is acceptable? If so, what would they be?

For example, is it acceptable to quickly format a hard drive that has been previously encrypted? If so, why? But because?