• 请不要在回答技术问题时复制粘贴 AI 生成的内容
kuingsmile
V2EX  ›  程序员

从 Google Authenticator 解密获取 2FA 密钥进行备份和平台转移的方法

  •  1
     
  •   kuingsmile ·
    Kuingsmile · May 12, 2024 · 11077 views
    This topic created in 915 days ago, the information mentioned may be changed or developed.

    Google Authenticator 支持设备间转移和 google 云备份,但是在软件内不能直接查看到密钥,不能很方便的进行密钥的本地保存和备份,或者是迁移到其它 2FA 平台。这里介绍一个从 Google Authenticator 解密获取到 2FA 密钥的工具和使用方法。

    操作过程

    导出配置文件二维码

    1. 打开 Google Authenticator ,点击左上角的三条横线按钮,选择转移账号
    2. 选择导出账号
    3. 勾选需要导出的账号并点击下一步

    这里我们会看到一个二维码,截图保存为文件,比如ga.jpg。

    使用 decodeGoogleOTP 工具解码

    为了方便整个过程,我写了一个命令行工具 decodeGoogleOTP ,前往Github 下载页面,根据自己的平台,下载最新版本的工具。

    下载后解压,为了方便操作可以重命名一下,比如 windows 平台重命名为decodeGoogleOTP.exe,然后和ga.jpg放在一个文件夹下。

    decodeGoogleOTP 支持将结果导出为 csv 文件、json 文件、txt 文件或者二维码图片等多种格式。如果我们需要将结果导出为 json 文件,运行如下命令即可

    decodeGoogleOTP -i ga.jpg -c output.json
    

    输出的结果格式如下:

    [
      {
        "issuer": "",
        "name": "xx",
        "secret": "AAAAAAAAAAA",
        "type": "totp",
        "counter": 0,
        "url": "otpauth://totp/xx?secret=AAAAAAAAAAA"
      }
    ]
    

    其中secret字段就是 2FA 密钥,有了密钥就可以方便的转移到其它平台。而url可以用来生成二维码供其它 2FA 软件扫描导入,也可以使用 decodeGoogleOTP 直接导出二维码图片供扫描

    更详细的使用方法参考下面的说明

    $ decodeGoogleOTP -h
    
    decodeGoogleOTP is a command line tool to decode Google OTP QR codes. Output can be json, csv, qrcode or plain text.
    
    Usage:
      decodeGoogleOTP [flags]
      decodeGoogleOTP [command]
    
    Available Commands:
      completion  Generate the autocompletion script for the specified shell
      help        Help about any command
      version     Print current version of the application
    
    Flags:
      -c, --csv string      Output in CSV format and specify the output file
      -d, --debug           Enable debug mode
      -h, --help            help for decodeGoogleOTP
      -i, --input string    Input file path
      -j, --json string     Output in JSON format and specify the output file
      -p, --print-qr        Print QR code to terminal
      -q, --qrcode string   Output in QR code image format and specify the output directory
      -s, --silent          Enable silent mode
      -t, --text string     Output url list in plain text format and specify the output file
      -u, --url string      Output in URL format and specify the output file
      -v, --version         Print version information
    
    Use "decodeGoogleOTP [command] --help" for more information about a command.
    
    21 replies  •  2026-03-13 15:39:03 +08:00
    YGHMXFAL
    YGHMXFAL
    May 12, 2024
    1
    不如改变习惯:

    每次添加 2FA,先使用 https://f-droid.org/packages/com.atharok.barcodescanner/ 这个开源离线 APP 来解码成字符串并且保存,再正常走 2FA 绑定流程
    xiaobai332
    xiaobai332
    May 12, 2024 via Android
    2
    或许可以下载开源软件 2fas ,扫码导入谷歌验证器中的所有 2fa ,直接看各个密钥(缺点大概是得一个一个看!?)
    uuhhme
    uuhhme
    May 12, 2024 via Android
    3
    直接转到 ente auth 就可以了。之后随时可以看
    ltkun
    ltkun
    May 12, 2024 via Android
    4
    找个开源的用比如 aegis
    hnliuzesen
    hnliuzesen
    May 12, 2024
    5
    @xiaobai332
    2FAS 如果有 root 权限还可以直接从谷歌验证器导入
    xxbing
    xxbing
    May 12, 2024
    6
    @YGHMXFAL #1 我也是这么做的,我单独下载一个二维码扫码的 app,绑 2FA 前先用 扫码 APP 扫一下,再用 google auth 扫描绑定. 二维码 APP 还有扫码历史记录
    xxbing
    xxbing
    May 12, 2024
    7
    @YGHMXFAL #1 为了防止二维码 APP 泄密,我还在设置里面,禁用了它的上网权限.
    Achophiark
    Achophiark
    May 12, 2024
    8
    keepass 等已经集成了,很方便了,为什么不用
    YGHMXFAL
    YGHMXFAL
    May 12, 2024
    9
    @xxbing #7 我也是,这样完全不被捆绑在任何 2FA 上
    mahaoqu
    mahaoqu
    May 12, 2024
    10
    MS Authenticator 怎么办
    Andim
    Andim
    May 12, 2024
    11
    @mahaoqu 不管 google 还是 ms 都可以解除现有 2FA ,然后重新绑定,记得保存那个二维码,用时不会超过 2 分钟,还不会有外泄风险
    cioccamilosch697
    cioccamilosch697
    May 12, 2024
    12
    @YGHMXFAL 你是真不怕密钥泄露,不如买个硬件安全密钥存里面双备份即可
    YGHMXFAL
    YGHMXFAL
    May 12, 2024
    13
    @cioccamilosch697 怎么泄露?安装扫码器就禁止它联网了,解码成字符串就加密同步到电脑
    BeautifulSoap
    BeautifulSoap
    May 12, 2024 via Android❤️2
    14
    全交给 bitwarden 了至少没那么麻烦

    包括谷歌认证在内一堆 app 连导出都麻烦的一批,谁爱用谁用
    6bsLo69Qdu3RPY4c
    6bsLo69Qdu3RPY4c
    May 13, 2024
    15
    和 Google 比我不相信你们的产品。反正我用谷歌,你们爱用不用
    dislazy2023
    dislazy2023
    May 13, 2024
    16
    我自建了 bitwarden rust 版本 用了好几年了
    dfdd1811
    dfdd1811
    May 17, 2024
    17
    阿里云的 mfa 能不能解成密钥,他那个导出出来的密钥没法导入别的软件,真狗啊…
    xwh
    xwh
    May 20, 2024
    18
    @dfdd1811 #17 确实,一直在找可以把阿里云 mfa 解密的方法,但是一直没找到
    huchenz1in
    huchenz1in
    Dec 19, 2024
    19
    现在貌似导出的时候有两个二维码了
    crossggc
    crossggc
    Jan 12
    20
    好用,感谢
    mikaelson
    mikaelson
    Mar 13
    21
    @dfdd1811 2026 了,有解决办法了吗?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   942 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 50ms · UTC 21:56 · PVG 05:56 · LAX 13:56 · JFK 16:56
    ♥ Do have faith in what you're doing.