AI Model Encryption: Best Practices for Protecting Data at Rest and in Transit

2025.10.17.
AI Security Blog

Your AI Model is Your Company’s Brain. Are You Storing It in a Shoebox?

Let’s get something straight. Your new, state-of-the-art, multi-million-dollar AI model isn’t just a chunk of code. It’s not another binary you ship. It’s the distilled essence of your proprietary data, your R&D, your competitive edge. It’s the Coca-Cola formula, the Colonel’s secret recipe, the blueprints to the Death Star all rolled into one. It’s your company’s brain, downloaded into a file.

So let me ask you a question. Why are so many of you leaving it lying around, completely unprotected?

Kapcsolati űrlap - EN

Do you have a question about AI Security? Reach out to us here:

I’ve seen it all. Models sitting in public S3 buckets. Models passed around in Slack DMs. Models on a developer’s unencrypted laptop left at a coffee shop. You might be thinking, “It’s just weights and biases, a bunch of numbers. Who cares?”

You should. An attacker with your model file can do more than just replicate your service. They can dismantle it. They can poison it. They can extract the very secrets you trained it to protect. This isn’t theoretical FUD; it’s happening right now.

We’re going to talk about encryption. But not the boring, checkbox-compliance kind. We’re talking about a multi-layered defense strategy for your model: at rest, in transit, and the one everyone forgets—in use. Buckle up.

What a Thief Can Actually Do With Your Stolen Model

Before we dive into solutions, you need to feel the fear. You need to understand what’s at stake. Grabbing your model.pth or saved_model.pb file isn’t just about a competitor stealing your work. It’s a launchpad for far more sinister attacks.

Model Inversion: Squeezing Your Training Data Out

This is the big one. Model Inversion is a technique where an attacker uses your model’s outputs to reverse-engineer the data it was trained on. Think of a painter who can look at a portrait and perfectly reconstruct the face, bone structure, and even the mood of the person who sat for it. An attacker does the same, but with your data.

Imagine you’ve trained a medical imaging model to detect cancer. An attacker steals it, and through clever queries, starts reconstructing images of the actual patient scans used in training. Suddenly, sensitive, private medical data is leaking out of a system that was supposed to be secure. The model itself becomes a backdoor to your most confidential information.

Membership Inference: The “Were You There?” Attack

This is a nasty little privacy violation. A membership inference attack allows an adversary to determine whether a specific individual’s data was part of your model’s training set.

Let’s say a bank trains a model to predict loan defaults. An attacker gets the model. Now, a shady data broker can use it to check: “Was John Doe’s financial profile, who was recently denied a loan, part of the high-risk training data?” A ‘yes’ answer can be sold, used for blackmail, or to target vulnerable individuals. It confirms a person’s presence in a dataset they never consented to be publicly identified in.

Offline Adversarial Attacks: Forging the Perfect Key

You’ve probably heard of adversarial attacks—crafting special inputs to fool a model, like a weird sticker on a stop sign that makes a self-driving car see a “Speed Limit 100” sign. Most defenses against these rely on the attacker having to probe your live model, which lets you detect and block them.

But if they have the model file? Game over.

They can run millions of simulations on their own hardware, completely offline, to craft the perfect, undetectable adversarial example. It’s the difference between a bank robber trying to guess a vault combination on-site with alarms blaring, versus having the vault blueprints at home to practice on for months. When they finally launch the attack against your live system, it will be a single, perfect shot that sails right through your defenses.

Golden Nugget: A stolen AI model is not just a loss of intellectual property. It’s a critical vulnerability that can be exploited to extract training data, violate user privacy, and craft unstoppable attacks against your live systems.

Fort Knox for Files: Encryption at Rest

Okay, you’re convinced. You need to lock this thing down. The first and most obvious state to protect is when the model is “at rest”—sitting on a disk, in a cloud storage bucket, or in a database. This is your foundation.

The First Layer: Storage-Level Encryption (The Lazy Option)

This is the easy button. When you create an S3 bucket in AWS, you can check a box for Server-Side Encryption (SSE-S3). Azure has Storage Service Encryption. Google Cloud has server-side encryption by default. This encrypts the data on the physical disk.

Is this enough? Absolutely not.

Think of it like this: storage-level encryption is like having security guards at the main entrance of a massive office building. They check IDs at the door. But once you’re inside, every office door is unlocked. If an attacker compromises a system that has legitimate access to that storage (like a CI/CD server or a developer’s account), they can read the model file as if it were unencrypted. The encryption is transparent to anyone with IAM access.

It’s a necessary baseline, like locking your car doors. It stops casual theft, but it won’t stop a determined professional.

The Real Deal: Application-Level Encryption

This is where you take control. Instead of letting the storage provider handle it, you encrypt the model file before you even write it to disk. Your application holds the key, not the storage system.

The workflow looks like this:

  1. Your training script finishes and produces final_model.h5.
  2. Before uploading, your script calls an encryption library (like OpenSSL or a language-specific crypto library).
  3. It encrypts final_model.h5 into final_model.h5.enc using a specific data key.
  4. You upload the encrypted .enc file to your S3 bucket.

Now, even if an attacker compromises your S3 bucket, all they get is a useless blob of encrypted data. They can’t do anything without the key.

The “Layers of the Onion” for Data at Rest Layer 1: Full Disk / Storage Encryption (e.g., AWS S3 SSE, BitLocker) Layer 2: Application-Level Encryption Model File Key Management: The Real Challenge (KMS, HSM)

This leads to the million-dollar question: where do you put the key?

Key Management: Don’t Hide Your Keys Under the Doormat

If you encrypt the model but hardcode the key in your application’s source code or a config file, you’ve accomplished nothing. That’s the digital equivalent of taping the key to the front door.

The solution is a dedicated Key Management Service (KMS).

  • Cloud KMS: Services like AWS KMS, Azure Key Vault, and Google Cloud KMS are the modern standard. They manage the lifecycle of your cryptographic keys. Your application doesn’t get the key itself; instead, it gets temporary credentials and asks the KMS to perform encryption or decryption operations on its behalf. Access is controlled via strict IAM policies. You can grant a specific server role permission to use a key to decrypt a model, but not to view the key material itself.
  • Hardware Security Module (HSM): For the truly paranoid (or highly regulated), an HSM is a physical piece of hardware designed to be a tamper-proof vault for cryptographic keys. It’s slower and more expensive, but it provides the highest level of assurance that your keys can never be exfiltrated. Cloud providers offer HSM-as-a-service options.

Using a KMS is a non-negotiable part of a serious encryption strategy. It separates the encrypted data from the ability to decrypt it.

Practical Comparison: At-Rest Encryption Methods

Method Granularity Key Control Protection Against… Best For
Storage-Level Encryption
(e.g., SSE-S3)
Entire bucket/disk Managed by cloud provider Physical theft of disks from a data center. A baseline, “checkbox” security measure. Better than nothing.
Application-Level Encryption
(with KMS)
Per-object / Per-file You control the keys and access policies via KMS. Compromised credentials, misconfigured storage permissions, insider threats. Protecting high-value assets like AI models where granular control is critical.

The Great Escape: Encryption in Transit

Your model doesn’t just sit on a disk forever. It moves. It gets downloaded by inference servers. It’s called via API. Every time it travels across a network, it’s vulnerable to a man-in-the-middle (MITM) attack, where an attacker intercepts and potentially alters the traffic.

TLS: The Armored Truck of the Internet

Transport Layer Security (TLS) is the protocol that powers HTTPS. It’s the standard for encrypting data in transit. You should be using it for every single network call, no exceptions.

But just “using TLS” isn’t enough. The devil is in the details.

  • Enforce Modern Versions: You must disable old, broken protocols like SSLv3, TLS 1.0, and TLS 1.1. Only allow TLS 1.2 and, preferably, TLS 1.3.
  • Use Strong Cipher Suites: A cipher suite is the combination of algorithms used for encryption. Some older ones are weak and easily broken. Your server configuration should enforce a policy of strong, modern ciphers.
  • Certificate Management: Don’t use self-signed certificates in production! Use a trusted Certificate Authority (CA) and automate your certificate renewal. An expired certificate is as bad as no certificate at all.

Think of TLS as an armored truck. Using TLS 1.3 with strong ciphers is a state-of-the-art Brinks truck. Using an old, misconfigured TLS 1.0 is like using a rusty 1980s van with a padlock on the back. Both are “armored trucks,” but one is clearly not up to the job.

Beyond the Edge: The Case for Mutual TLS (mTLS)

Standard TLS is a one-way street. Your client (like an inference server) verifies the identity of the server (like your model registry) by checking its certificate. The client knows it’s talking to the real server.

But the server has no idea who the client is. It just accepts the connection.

This is fine for the public internet, but inside your own network, you should be more paranoid. The old “castle and moat” security model, where the perimeter is hard but the inside is soft and squishy, is dead. Assume an attacker is already inside your network. Assume your internal network is hostile.

This is where Mutual TLS (mTLS) comes in. With mTLS, it’s a two-way street. The client verifies the server’s certificate, AND the server verifies the client’s certificate. Both parties must prove their identity before a connection is established.

It’s the difference between showing your ID to a bouncer to get into a club (TLS), and a speakeasy where you have to show your secret membership card and the bouncer has to give you the secret password in return (mTLS).

For your MLOps pipeline, this is critical. The service that fetches the model for deployment should have to present its own client certificate to the model registry. The inference server calling a feature store API should have to present its certificate. This prevents a rogue service that has popped up inside your network from accessing sensitive AI components.

Standard TLS Client Server 1. Hello, here’s my list of ciphers. 2. OK. Here’s my Certificate. Prove it’s me. 3. Verified! Let’s talk securely. Mutual TLS (mTLS) Client Server 1. Here’s my Certificate. 2. Verified! Now, you show me YOURS. 3. Here you go. 4. Verified! Let’s talk securely. mTLS: Trust is a two-way street. Both parties verify each other.

The Final Frontier: Protecting Data in Use

This is the part that separates the amateurs from the professionals. You’ve encrypted your model at rest. You’ve encrypted it in transit. You’re feeling pretty good.

But what happens when you actually need to use the model for inference?

To perform the calculations, the CPU needs the model weights and the input data in plaintext. This means your inference server has to download the encrypted model, use a key from the KMS to decrypt it, and load the plaintext model into memory (RAM). At that moment, your precious, protected model is completely vulnerable.

An attacker who gains root access to that server—via an unpatched vulnerability, a stolen SSH key, whatever—can simply dump the process’s memory to a file. And voilà, they have your decrypted model and potentially the decryption key as well. All your hard work on at-rest and in-transit encryption is undone in an instant.

Golden Nugget: If your model is decrypted into the general-purpose memory of a server, it is vulnerable. The root user (and therefore a determined attacker) on that machine can always access it.

So how do we solve this? How do we compute on data without exposing it? Welcome to the cutting edge of security: confidential computing.

Confidential Computing: The Black Box in the CPU

The core idea behind confidential computing is to create a secure, isolated area within the CPU itself. This is called a Trusted Execution Environment (TEE) or a Secure Enclave.

Think of it as a tiny, impregnable black box inside your main processor. Your application can load encrypted code and data into this box. The CPU decrypts it inside the enclave, performs the computation on the plaintext data, and then encrypts the result before sending it back out.

The critical part? Nothing outside the enclave can see what’s happening inside. Not other processes, not the operating system, not the hypervisor, not even the cloud provider who owns the physical hardware. The decryption and computation happen in a space that is cryptographically sealed off from the rest of the world.

Technologies that enable this include:

  • Intel SGX (Software Guard Extensions)
  • AMD SEV (Secure Encrypted Virtualization)
  • AWS Nitro Enclaves

Your MLOps workflow now looks like this: the inference server launches inside a secure enclave. It requests the encrypted model. It uses a key (which is also protected by the enclave) to decrypt the model into the enclave’s private memory. When an inference request comes in, the input data is also passed into the enclave, processed, and the result is passed out. Your model is never, ever present in plaintext in the main server’s RAM.

Confidential Computing with a TEE / Secure Enclave Host System (Untrusted) Operating System, Hypervisor, Other Processes Secure Enclave (TEE) (Cryptographically Isolated) Decrypted Model + Plaintext Data Encrypted Model/Data IN Encrypted Result OUT Even the Host OS/Admin cannot see inside the enclave!

Homomorphic Encryption: The Holy Grail (That’s Not Quite Here Yet)

There’s one more concept you need to know about: Homomorphic Encryption (HE).

HE is a form of encryption that allows you to perform computations directly on encrypted data without ever decrypting it. Imagine you have two encrypted numbers, ENC(5) and ENC(10). With HE, you could have a special function, HE_ADD(ENC(5), ENC(10)), that produces ENC(15). You just added two numbers together without ever knowing what they were.

It’s the ultimate in data privacy. The analogy is a locked glove box. You can put your hands into special sealed gloves attached to the box and manipulate the contents (e.g., assemble a watch) without ever opening the box or seeing the parts directly.

So why aren’t we using this for everything? Performance. The computational overhead of HE is astronomical. An operation that takes a nanosecond on plaintext data might take minutes or hours with current HE schemes. It’s simply not practical for the complex matrix multiplications required by today’s deep learning models.

It’s an area of intense research, and it may be the future, but for now, it’s not a solution you can deploy for your ResNet-50 model. Confidential computing in TEEs is the practical, available solution for protecting data in use today.

Practical Comparison: In-Use Protection Methods

Method Security Guarantee Performance Maturity Best For
Standard Memory None. Vulnerable to memory dumping by privileged users. Highest Universal Non-sensitive models and data where performance is the only concern. (Risky!)
Confidential Computing (TEEs) Protects against OS, hypervisor, and physical access. Small overhead (typically 5-20%). Production-ready (AWS Nitro, Azure CC, Google CVM). The current best practice for securing sensitive AI workloads in the cloud.
Homomorphic Encryption (HE) Protects against everyone, always. Data is never decrypted. Extremely slow (1000x+ overhead). Research / Niche applications. Simple computations on highly sensitive data where performance is not a factor.

Putting It All Together: An End-to-End Secure MLOps Workflow

Theory is nice. Let’s walk through a concrete, secure lifecycle for your AI model.

End-to-End Secure Model Lifecycle 1. Training Produces model.pth 2. Encryption Encrypt with key from KMS KMS 3. Storage model.pth.enc in S3 CI/CD Pipeline 4. Deployment Host (Untrusted) 5. Secure Enclave (TEE) a) Fetch encrypted model b) Get decryption key from KMS c) Decrypt model in enclave d) Serve requests 6. Inference Request (via mTLS) Key: States and Transitions Data/Process Encryption Step Secure State Untrusted/Vulnerable
  1. Training: Your model is trained as usual. The output is a plaintext model artifact (e.g., model.pth). This artifact is sensitive from the moment it is created.
  2. Encryption at Birth: Your training or CI/CD pipeline immediately calls a KMS. It requests the KMS to generate a data key, uses it to encrypt the model file (creating model.pth.enc), and then the KMS encrypts the data key itself using a master key that never leaves the KMS. The encrypted model and the encrypted data key are stored together.
  3. Secure Storage: The encrypted artifact (model.pth.enc) is uploaded to your model registry or artifact store (like S3 or Artifactory). You still enable server-side storage encryption as a defense-in-depth measure.
  4. Secure Deployment: Your inference service, running inside a Confidential Computing environment (like an AWS Nitro Enclave), is given a specific IAM role. This role grants it permission to access the encrypted model from storage and permission to talk to the KMS.
  5. Decryption in the Vault: The service starts.
    • It downloads the encrypted model file.
    • It sends the encrypted data key to the KMS and asks it to decrypt it. The KMS verifies the service’s IAM role and, if valid, returns the plaintext data key. This entire transaction happens over a secure channel.
    • The service uses the plaintext data key to decrypt the model directly into the enclave’s protected memory.
    • The plaintext data key is immediately discarded. The model now lives, unencrypted, but only inside the secure black box.
  6. Serving Requests: A client makes an inference request to your API endpoint. The connection is established using mTLS, where both the server and the client must prove their identities. The request data is passed into the enclave, processed by the model, and the result is passed back out to the client over the secure mTLS channel.

In this entire flow, your model is only ever in plaintext inside a cryptographically sealed environment that no one can peer into. It is never exposed in general-purpose memory, on disk, or on the network. That is a truly secure lifecycle.

Stop Making Excuses

I hear the objections already. “This sounds complicated.” “It’ll add latency.” “We don’t have the resources.”

Is it more work than just dumping a file in a bucket? Yes. Does it require you to learn about new technologies like KMS and confidential computing? Yes. But the alternative is leaving your company’s single most valuable digital asset exposed to the world.

The tools to do this are more accessible than ever. Cloud providers have made KMS a few clicks away. Confidential computing VMs are now available on all major clouds. The cost and performance overhead are minimal for the massive leap in security you achieve.

Encrypting your AI models isn’t a feature. It’s not a “nice-to-have.” It’s a fundamental requirement for doing business in a world where data is both your greatest asset and your greatest liability.

So, take another look at your MLOps pipeline. Ask the hard questions. Where does your model live? How does it travel? Where is it decrypted? If you don’t have good answers for all three, you have work to do.

Your company’s brain is in your hands. Don’t be the one who leaves it on the sidewalk.