Open-source project
orhanobut/hawk avatar
orhanobut/hawk

Hawk 2.0.1 may store your values as Base64 only, and Hawk 3 cannot read what it wrote

✔️ Secure, simple key-value storage for Android

3,992 stars393 forksKotlinApache-2.0

At a glance

What is it?
orhanobut/hawk is a key-value store for Android on top of SharedPreferences. The published 2.0.1 release dates from 2018 and uses legacy Conceal encryption with a possible Base64-only fallback, while the unreleased Hawk 3 switches to Android Keystore and breaks compatibility.
Who is it for?
Use Hawk 2.0.1 for simple, non-secret preferences where a small synchronous API and Gson serialization are enough, and treat its encryption as unreliable because it can fall back to Base64. Do not use it for secrets or plan a Hawk 3 migration until that version ships, because the README says Hawk 3 cannot read Hawk 2 ciphertext.
Can I use it commercially?
Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 53 days ago.
What is it written in?
Mainly Kotlin, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • orhanobut/hawk3,992 ★ · -1
Star history
Repository2026-10-092026-11-25
orhanobut/hawk4k4k

-1 Stars in the last 47 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

The published 2.0.1 artifact may quietly store values as Base64

The README warns that published Hawk 2.0.1 still uses legacy Conceal and may fall back to Base64-only storage. The installation snippet does not change that behavior. If Conceal cannot be used on a device, your supposedly encrypted values are readable by anyone who can open the preferences file and decode Base64.

There is also a class for choosing that outcome on purpose. NoEncryption is available for data that needs no confidentiality, and it only Base64-encodes values. Base64 is an encoding, not protection, and the README is explicit about it.

The repository description calls Hawk secure, but the text of the README is more careful. Anything you store through Hawk 2.0.1 should be treated as obfuscated at best. If the value is a token or credential, keep it out of Hawk until a release with Keystore-backed encryption exists. The last tagged release is 2.0.1 from 2018-04-03, and the two before it are 1.23 and 1.22 from 2016.

The Hawk 3 notes describe the opposite stance. There, initialization fails if Keystore is unavailable rather than quietly degrading. That choice trades availability for honesty: an app on a device without Keystore would refuse to start Hawk instead of storing readable text. Until that version ships, the safe assumption for 2.0.1 is that you cannot tell from the API alone which of the two modes a given device ended up in.

Hawk 3 is announced, unreleased, and will not read Hawk 2 ciphertext

A banner at the top of the README says Hawk 3 is coming soon, with Android Keystore-backed AES-GCM encryption, fewer dependencies and a modern Kotlin codebase. It also says Hawk 3 is not released and the current published version is 2.0.1. The repository's last push was 2026-10-03, so work is happening, but no tag has followed.

The planned version uses AES-256-GCM with an application-owned Android Keystore key. Each write uses a fresh nonce and binds the ciphertext to its storage key. Initialization fails if Keystore is unavailable, and it never falls back to NoEncryption. It requires Android 6.0 (API 23) or newer, while the published 2.0.1 artifact declares API 10 as its minimum.

The break is hard. Hawk 3.0 cannot read Hawk 2's default ciphertext, and ConcealEncryption has been removed. You must read and migrate values with the old library first, then save them with the new encryption. Unmigrated values stay on disk, and get returns null or your default when decryption fails. They are not cleared or converted automatically.

There is one carve-out. Applications storing non-sensitive data with NoEncryption can explicitly keep that implementation, which avoids the migration for data that never needed protecting. For everything else, plan the migration as a release of its own: ship a version that reads old values and rewrites them, and only then adopt the new library.

Setup is one init call with an application context

The dependency comes from Maven Central:

kotlin
repositories {
    mavenCentral()
}

dependencies {
    implementation("com.orhanobut:hawk:2.0.1")
}

Initialize once with an application context, before any read or write. Passing an activity context would leak it, so use applicationContext as the example does.

kotlin
Hawk.init(applicationContext).build()

val saved = Hawk.put("name", "Ada")
val name: String? = Hawk.get("name")
val visits: Int = Hawk.get("visits", 0)

Hawk.put("tags", listOf("android", "kotlin"))
val tags: List<String>? = Hawk.get("tags")

Hawk.contains("name")
Hawk.count()
Hawk.delete("name")
Hawk.deleteAll()

The examples use APIs available in 2.0.1. You can store primitives, strings, custom objects, lists, sets and maps, and values persist in app-private SharedPreferences, so no database schema is involved.

Return values and null handling follow a few fixed rules

put returns whether the value was saved, so check it if losing a write matters. Passing a null value deletes the key instead of storing null. A missing key returns null, or the default you supply, as visits does with 0.

deleteAll clears stored values but retains encryption keys. That keeps other stored data decryptable in the Keystore design, and it means a wipe does not rotate the key.

Reads and writes are synchronous. The README tells you to perform substantial work away from the main thread, which matters for large lists or maps, because serialization with Gson and the SharedPreferences write both happen on the calling thread. A small string is fine on the main thread, and a long list of objects is the case to move.

The small API also covers contains, count and delete, so there is nothing for querying: you look values up by exact key, and you cannot search by value.

The defaults matter more than they look. Hawk.get("visits", 0) returns an Int and never null, which spares a null check for counters and flags, while Hawk.get("name") returns a nullable String that you must handle. If a key exists but decryption fails, you get the same null or default as for a missing key, so a failed read and an absent value look identical to the caller.

Every stage of the pipeline can be swapped, and Gson is the default parser

Hawk calls itself pluggable. Parsing, conversion, encryption, serialization and storage can each be customized. Gson is the default parser, so a configured GsonParser is how you supply custom type adapters.

kotlin
Hawk.init(applicationContext)
    .setParser(GsonParser(GsonBuilder().create()))
    .setStorage(myStorage)
    .setEncryption(myEncryption)
    .build()

SetParser, setStorage and setEncryption each take your own implementation of the matching interface. The same builder is where you would choose NoEncryption, and the Hawk 3 notes mention a KeystoreEncryption constructor that takes an alias. Keep that alias unchanged while its data is retained, or the data becomes unreadable.

The README warns that changing encryption, parsing or storage implementations does not migrate existing data. Swapping a component is therefore a data-compatibility decision and not just a refactor, and the same rule applies to Hawk 2 data being incompatible with Hawk 1.

In practice that means a custom Gson parser is the right place for date formats and polymorphic types, and a custom storage class is the place to move values off SharedPreferences. Each swap touches only the stage it names, but the saved bytes change, so test the read path on a device that already holds old data before you release.

Type rules, R8 and backups are where saved values go missing

Use the same type when reading a key as when saving it. Collections record the class of the first element, so use homogeneous, non-nested collections whose first element, and the first map key and value, is non-null. Model changes can prevent older data from being read, and Gson does not enforce Kotlin constructor defaults or non-null properties, so a stored object can come back with a null in a field you declared non-null.

With R8, keep the names and fields of persisted models, because the format stores class names and Gson uses reflection:

proguard
-keep class com.example.app.storage.model.** { *; }

Replace the package with your own. Renaming a persisted class in a release build is a silent way to lose data.

Keystore keys are not restored with preferences or moved to another installation. Exclude Hawk2.xml from both cloud backup and device transfer using your app's backup rules, or restored values cannot be decrypted. Hawk never regenerates a key while decrypting an existing value, so key loss has to be handled by recovering data from a trusted application-specific source. Avoid logging sensitive data through a LogInterceptor.

Maintenance is a gap between tags and a recent push

The repository is not archived. Its last push was 2026-10-03, which is within six months, but the newest tag is 2.0.1 from 2018-04-03. Code has moved in the repository without a published artifact, so what Maven Central serves is eight years behind the master branch.

Top-level entries show the shape of the project: a hawk/ module, a benchmark/ folder, a CHANGELOG.md, a MAINTAINING.md, and Gradle Kotlin DSL build files. The README has a section titled How values are stored that contains no text, so the storage format is not documented there. The license is Apache-2.0, credited to Orhan Obut.

That gap defines the adoption risk. If you depend on 2.0.1 you get the 2018 behavior, including the Conceal fallback, and you inherit a later migration when Hawk 3 is released. If you build from master you take on unreleased code with a different encryption format. Neither route gives you a stable, current, encrypted store today, and the README does not offer a date for Hawk 3.

Editorial conclusion

Use Hawk 2.0.1 for simple, non-secret preferences where a small synchronous API and Gson serialization are enough, and treat its encryption as unreliable because it can fall back to Base64. Do not use it for secrets or plan a Hawk 3 migration until that version ships, because the README says Hawk 3 cannot read Hawk 2 ciphertext. Before adopting, decide how you will exclude Hawk2.xml from backups and what you will do if decryption returns null.

Frequently asked questions

Is Hawk's encryption safe in version 2.0.1?

Not reliably. Published Hawk 2.0.1 uses legacy Conceal and may fall back to Base64-only storage, and NoEncryption only Base64-encodes values.

Can Hawk 3 read data saved by Hawk 2?

No. Hawk 3.0 cannot read Hawk 2's default ciphertext, so you must read and migrate values with the old library, then save them with the new encryption.

How do I add Hawk to an Android project?

Add mavenCentral() to repositories and implementation("com.orhanobut:hawk:2.0.1") to dependencies, then call Hawk.init(applicationContext).build() once before any read or write.

Official sources

  1. Issues
  2. License: Apache-2.0
  3. orhanobut/hawk on GitHub
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/orhanobut-hawk.svg)](https://hysenlabs.com/projects/orhanobut-hawk)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/orhanobut-hawk.svg)](https://hysenlabs.com/projects/orhanobut-hawk)

Was this useful?