Tutorial  Updated

How to get Switch Keys for Hactool/XCI Decrypting

This thread is deprecated
For a faster, easier and more up-to-date way of getting keys use Lockpick_RCM by shchmue
If you still want to follow this tutorial and end up with less keys, continue reading the Thread.


WARNING
  • DO NOT GIVE OUT ANY OF YOUR KEYS TO ANYONE! I CANNOT STRESS THAT ENOUGH!
  • DO NOT SHARE YOUR KEYS BETWEEN MULTIPLE SWITCHES THAT YOU DO/DON'T OWN! SOME ARE CONSOLE-UNIQUE
  • DO NOT ASK ME FOR KEYS


LEGEND
  • SBK
    SecureBootKey
  • TSEC
    Tegra Security Co-processor Key
  • eMMC
    Embedded MultiMediaCard (Switch's Onboard Storage)


GOAL
End up with 83+ keys including SBK and TSEC keys. Get Master Key's 0-5. (Master Keys 6 onwards is not done in this tutorial)
Reminder, if you want more up-to-date and much more convenient way to get your Switch's Keys, use Lockpick by shchmue (available in nx-appstore/homebrew store)


Tutorial — (Outdated for Switch's on firmware 6.x or newer)


#1 - Dumping System Keys (Biskeydump)#2 - Dumping Required Files#3 - Hactool Preparation#4 - Dumping KeysFinal WordsTroubleshooting


  1. We need to get your Secure Boot Key (SBK) and Tegra Security Co-processor Key (TSEC) before we can get the main keys.
    These are 100% console unique.

    1. Download and extract biskeydump.bin from biskeydumpvx.zip
      - Follow this tutorial but instead of using CTCaer's Hekate Mod .bin file, use the biskeydump.bin file
      - If the QR Code is Blue, Scan the QR Code with your Phone, Laptop e.t.c
      - If you cant find a device you can scan with, type them out into your PC/Laptop (Its highly recommended to scan the QR Code, as a lot of characters can look like another, O0, Il, rn can look like m, e.t.c)
    2. Once you have the biskeydump of your System, store all the keys you received somewhere safe, I recommend a secure cloud storage aswell as a USB Stick, perhaps even print it.
      - Don't give this to ANYONE, Seriously.

    If you get any errors please go to the Troubleshooting Tab.


    1. Follow this tutorial AGAIN but this time use CTCaer's Hekate Mod.
      - "Tools" -> "Backup..." -> "Backup eMMC BOOT0/1"
      - "Tools" -> "Backup..." -> "Backup eMMC SYS"
      - Back all the way to the first menu, and choose "Power off"
    2. Take the microSD Card out of your Switch and into your PC.
    3. Copy both "BOOT0" and "BCPKG2-1-Normal-Main" from "sd:/backup/xxxxxx/" (xxxxxx is different for everyone) to "hactool" on your Desktop (create the "hactool" folder)
      - Rename them with .bin at the end, "BOOT0.bin", "BCPKG2-1-Normal-Main.bin"

    1. Download and install Python 2.7.x - NOT Python 3.x.x
      When installing, it will ask you what features you want installed, scroll to the bottom and make sure "Add Python to Path" has "Entire Feature Installed to HDD" option chose (No Red X Icon), otherwise the scripts wont find Python and WILL fail
    2. Download and extract hactool TO THE DESKTOP AND NAME THE FOLDER "hactool"
      On Linux/MacOS: clone and build hactool manually
    3. Right-click this (script originally by tesnos6921, patched by shadowninja108, jakibaki and shchmue)
      - Click "Save link as" / "save as"
      - Set "Save as type" to "All Files"
      - Name it "keys.py"
      And finally save it to the hactool folder you placed in the Desktop.
      NOTICE TO GBATEMP STAFF: The "keys" inside this file, are NOT keys, they are SHA digest hashes used to search through files to find text that matches, which would be the keys.

    1. Press WIN(Btn)+R to open "Run", type "cmd" and press Ctrl+Shift then Enter to open Command Prompt as an Administrator
    2. Type (in order) or Copy the following and paste into Command Prompt (Some Windows Versions use Right Click to Paste, some use CTRL+C)
      python -m pip install --upgrade pip
      pip install lz4
      cd Desktop/hactool

      python keys.py SBK_Here_From_Biskeydump TSEC_Here_From_Biskeydump
    3. It should say: "Now you can do hactool --keyset=keys.txt to use them!", if it does, and there's no warning messages, you're good to go! :O
    If you get any errors please go to the Troubleshooting Tab.

  2. You now have a keys.txt file with your console-specific keys inside.
    Rename as needed by any software that requires a different name or file extension, it doesn't matter.
    Though I highly recommend renaming it to prod.keys as this filename for Key file's is becoming a popular choice with other software
    There may be more keys, as the Switch's lifecycle goes on, more and more keys will be needed as the firmwares grow and grow.
    • The Hactool warning:
      Code:
      [WARN] prod.keys does not exist.
      can be safely ignored.
      - if you want to place your "keys.txt" file their, put "keys.txt" on your Desktop and run the following with Administrator Command Prompt (Step #4.1 for instructions):
      Code:
      mkdir -p %USERPROFILE%\.switch
      move "%USERPROFILE%\Desktop\keys.txt" "%USERPROFILE%\.switch\prod.keys"

  3. #1 ISSUES:
    • Code:
      Red QR Code Outline
      - The reasons this can occur is quite a rarity, all I can say is to keep rebooting and trying again.
      - If there's a new version of biskeydump out, try using the newer biskeydump.bin
    • Code:
      QR Code not being scanned by your Reader
      - Align your QR Code Readers alignment overlay with the Blue Square's Corners/Edges, NOT the QR Code's Corners/Edges.
      - Clean your camera lens
      - Be in a bright room

    #4 ISSUES:
    • Code:
      File "keys.py", line ...
      print message
      ^
      SyntaxError: Missing parentheses in call to 'print'. Did you mean print(message)?
      - You didn't place SBK and TSEC in the 4th line of the Command in Step #4.2
      - You installed Python 3.x.x when you must use 2.7.x, uninstall python, logout of windows (important it removes python from PATH) and follow Step #3.2 then move back to #4.1
    • Code:
      import lz4.block
      File "C:\Python27\lib\site-packages\lz4\__init__.py", line 17, in <module>
      from ._version import ( # noqa: F401
      ImportError: DLL load failed: The specified module could not be found.
      - The 2nd line of the Command in Step #4.2 failed without you noticing. Try running the 1st line to upgrade pip and if that goes successfully run the 2nd line to install lz4 and see if it successfully installs.
 
Last edited by shchmue,

krptg

New Member
Newbie
Joined
Oct 1, 2018
Messages
2
Trophies
0
Age
31
Location
Paris
XP
128
Country
France
Hey guys one question, when I am trying toPrint TSEC keys it shows me an erros whom says: Could not identify package1 version to read TSEC firmware <= ´2018 and some other numbers ´> How can I fix it? and why does it happen to me?
Thanks :)

Facing the absolute same issue here. I did suceed with the payload with the QR code but then the OP script outputs a bunch of errors saying BOOT is corrupted.
If I can succeed in dumping with hekate, I could use kezplez to generate the rest of the keys...
 

neocero

New Member
Newbie
Joined
Oct 2, 2018
Messages
2
Trophies
0
Age
31
XP
44
Country
Argentina
Using BOOT0.bin to get keys from package1...
Could not find keyblob_key_source_xx! Please check the integrity of the data used in the current stage!

Getting this error message with the keys.py and firmware 6.0 on my switch.
Any help please?

Using BOOT0.bin to get keys from package1...
Injecting keyblob_key_sources
Deriving keys...
Decrypting package1...
Failed to decrypt PK11! Is correct key present?
Using Secure_Monitor.bin to get keys to decrypt package2...
Traceback (most recent call last):
File "kezplez.py", line 405, in <module>
TZ_f = open("package1/Secure_Monitor.bin", "rb")
IOError: [Errno 2] No such file or directory: 'package1/Secure_Monitor.bin'

And getting this error with the other script
 

datnodude

Active Member
Newcomer
Joined
Jul 6, 2018
Messages
40
Trophies
0
XP
302
Country
United States
i ran into the connection error installing lz4. throw this into a .py file and run it, will bypass https error

Code:
def install_and_import(package):
    import importlib
    try:
        importlib.import_module(package)
    except ImportError:
        import pip
        pip.main(['install', package])
    finally:
        globals()[package] = importlib.import_module(package)


install_and_import('lz4')
 

bazzarGBATEMP

New Member
Newbie
Joined
Oct 5, 2018
Messages
2
Trophies
0
Age
42
XP
54
Country
United States
if you want a computer based tool instead of running kezplez-nx just use HACGUI tbh. it requires a full rawnand dump but it’s super easy to use

I was having problems with the original way, however, your link was perfect. Gave me all of the keys within a minute. renamed the keys.ini to keys.dat and was using dOPUS to install XCIs within no time. You are a STAR!!!!
 

wolfidroid

Well-Known Member
Newcomer
Joined
Jul 4, 2018
Messages
66
Trophies
0
Age
50
XP
554
Country
Israel
I am getting an error message:
Using BOOT0.bin to get keys from package1...
Deriving keys...
Decrypting package1...
Using Secure_Monitor.bin to get keys to decrypt package2...
Decrypting package2...
Failed to decrypt PK21! Is correct key present?
Decompressing spl.kip1 and FS.kip1...
Traceback (most recent call last):
File "keys.py", line 409, in <module>
SPL_KIP1_f = open("ini1/spl.kip1", "rb")
IOError: [Errno 2] No such file or directory: 'ini1/spl.kip1'
 

konamicode89

Well-Known Member
Member
Joined
Mar 13, 2018
Messages
142
Trophies
0
Age
34
XP
773
Country
United States
can somebody kindly explain the difference between prod.keys and keys.txt? can I just rename prod.keys to keys.txt or am I missing an extra step here?
 

Cyan

GBATemp's lurking knight
Former Staff
Joined
Oct 27, 2002
Messages
23,749
Trophies
4
Age
45
Location
Engine room, learning
XP
15,648
Country
France
why not all tool use the same key filename/extension ?
how to know if a tool expect a different format, or just a file renaming of another existing key file?

are there different key files (apparently SBK and TSEC, prod.keys, keys.txt at least?), or are private keys stored in the keys.txt too ?
if private keys are in it, I guess using a random file found on internet is not a good idea.


@PRAGMA :
does this topic's first post need an update?
when I quickly read the pages, I noticed some users provided links to different scripts.
there are new script to use to extract more keys for example, or different method (kezplez python, kezplez-nx, kezplez-nx fork, hacgui, etc.)
Do we need to follow all the step of the guide "again" if we already have a dump of NAND from hekate? the guide tells to do it, but doesn't take in account users who already have some dumps. does it require a specific hekate payload, or all hekate version are fine (generated filename all similar, etc.)?

Also, not critisizing, but your hekate dumping guide only talk about RCM Smasher for windows+driver install, etc.. Some users might be on Mac, or want to use android, or other plateform. there are javascript and website too.
it would be nice to give choices, if you have time. I maintain a list of payload sender/injector on wikitemp if you need idea which one to use.
But I suppose a lot of users already have their own method to inject payloads, even using dongles.
 
Last edited by Cyan,
  • Like
Reactions: klear

shchmue

Developer
Developer
Joined
Dec 23, 2013
Messages
791
Trophies
1
XP
2,367
Country
United States
why not all tool use the same key filename/extension ?
how to know if a tool expect a different format, or just a file renaming of another existing key file?

are there different key files (apparently SBK and TSEC, prod.keys, keys.txt at least?), or are private keys stored in the keys.txt too ?
if private keys are in it, I guess using a random file found on internet is not a good idea.


@PRAGMA :
does this topic's first post need an update?
when I quickly read the pages, I noticed some users provided links to different scripts.
there are new script to use to extract more keys for example, or different method (kezplez python, kezplez-nx, kezplez-nx fork, hacgui, etc.)
Do we need to follow all the step of the guide "again" if we already have a dump of NAND from hekate? the guide tells to do it, but doesn't take in account users who already have some dumps. does it require a specific hekate payload, or all hekate version are fine (generated filename all similar, etc.)?

Also, not critisizing, but your hekate dumping guide only talk about RCM Smasher for windows+driver install, etc.. Some users might be on Mac, or want to use android, or other plateform. there are javascript and website too.
it would be nice to give choices, if you have time. I maintain a list of payload sender/injector on wikitemp if you need idea which one to use.
But I suppose a lot of users already have their own method to inject payloads, even using dongles.
this doesn’t extract personal keys and yes it needs an update for 6.0. different tools look for different file names but prod.keys has become standard. some tools let you specify the key filename. no need to make a new dump.
 

smileforthecamera

Member
Newcomer
Joined
Oct 5, 2018
Messages
12
Trophies
0
Age
28
XP
106
Country
United States
I've dumped boot0 twice now and copied them directly into the hactool folder and then add .bin to the end of them and it didnt work. it said could not find keyblob_key_source_xx. please help
 

quada

New Member
Newbie
Joined
Oct 9, 2018
Messages
1
Trophies
0
Age
33
XP
46
Country
United States
Also getting "Failed to decrypt PK21! Is correct key present?". Does the python script need an update for 6.0.0 firmware?
 

Dominator211

JFK's Jelly Donut
Member
Joined
Oct 15, 2016
Messages
1,818
Trophies
0
Location
The LaCrosse Field
XP
3,342
Country
United States
im getting this error here any help?
HERP A DURRFF.png
 

Hauteknits

New Member
Newbie
Joined
Jul 22, 2015
Messages
1
Trophies
0
Age
34
XP
55
Country
United States
im getting this error here any help?
View attachment 146434
run "pip install lz4"

--------------------- MERGED ---------------------------

on step 4 "Using BOOT0.bin to get keys from package1... Could not find keyblob_key_source_xx! Please check the integrity of the data used in the current stage!" I have lz4 installed and have tried this over 2 computers, both running python 2.7.15. With my switch on 6.0.1. I have extracted the keys twice, as well as switch the path for hactool from "hactool" to "./hactool". The command is (in admin cmd)> python keys.py <SBK key> <TSEC key>. Any ideas? Keys from biskeydump were also double checked (only sbk and tsec)
 

Draxzelex

Well-Known Member
Member
Joined
Aug 6, 2017
Messages
19,007
Trophies
2
Age
29
Location
New York City
XP
13,374
Country
United States
I'm on 6.0.1 and using a Mac. Is this tutorial still up to date?
OP hasn't been updated since June 16th and firmware 6.0 came out recently. There are much better ways of obtaining the keys such as shchmue's fork of kezplez or hacgui (I think hacgui only runs on Windows devices).
 

shchmue

Developer
Developer
Joined
Dec 23, 2013
Messages
791
Trophies
1
XP
2,367
Country
United States
it’s probably not a huge deal to fix this and iirc SocraticBliss did a few pages back but still needs 6.0 keyblob seeds but it’s useless if pragma doesn’t update the link
 

Site & Scene News

Popular threads in this forum

Recent Content

General chit-chat
Help Users
  • No one is chatting at the moment.
    Xdqwerty @ Xdqwerty: good night