bitwarden convert

import json
import csv
import os

# 配置:将你的 Bitwarden 导出文件名填在此处
INPUT_FILE = 'abc.json'
OUTPUT_FILE = 'abc.csv'

def convert():
    if not os.path.exists(INPUT_FILE):
        print(f"错误: 找不到文件 {INPUT_FILE},请确保导出的 JSON 在同一目录下。")
        return

    with open(INPUT_FILE, 'r', encoding='utf-8') as f:
        data = json.load(f)

    # Apple 钥匙串要求的标准表头
    header = ['Title', 'URL', 'Username', 'Password', 'Notes', 'OTPAuth']
    rows = []

    for item in data.get('items', []):
        if item.get('type') == 1:  # 仅处理登录信息 (Login)
            login = item.get('login', {})
            
            # 提取数据
            title = item.get('name', '')
            # 提取第一个 URI
            uris = login.get('uris', [])
            url = uris[0].get('uri', '') if uris else ''
            
            username = login.get('username', '')
            password = login.get('password', '')
            notes = item.get('notes', '')
            
            # 提取 2FA/TOTP 密钥
            totp = login.get('totp', '')
            otp_auth = f"otpauth://totp/{title}?secret={totp}" if totp else ""

            rows.append([title, url, username, password, notes, otp_auth])

    with open(OUTPUT_FILE, 'w', newline='', encoding='utf-8') as f:
        writer = csv.writer(f)
        writer.writerow(header)
        writer.writerows(rows)

    print(f"转换成功!生成文件: {OUTPUT_FILE}")
    print("提示:导入 Apple 钥匙串后,请务必彻底删除 JSON 和 CSV 原文件!")

if __name__ == "__main__":
    convert()
Scroll to Top