LoginSignup
2
2

More than 1 year has passed since last update.

mnbcard - マイナンバーカード PYTHON Lib

Last updated at Posted at 2022-07-09

概要

マイナンバーカードのPython用ツール・ライブラリーです。

できること

  • 券面確認 AP・券面入力補助 AP の読み取り
    • 4 属性の取得(名前、住所、生年月日、性別)
    • 個人番号の取得
  • 公的個人認証の各種証明書の読み取り
    • 認証用証明書の取得
    • 認証用証明書 CA の取得
    • 認証用証明書の取得
    • 署名用証明書 CA の取得
  • 公的個人認証の署名
    • 認証用秘密鍵による署名
    • 署名用秘密鍵による署名

ソースコード

使用例

#! /usr/bin/env python3

import logging
import sys
sys.path.append('./../mnbcard')

from reader import get_reader, connect_card
from api import *
from helper import *

# ログレベルを設定する
root = logging.getLogger()
root.setLevel(logging.DEBUG)

# ログをコンソールに出力
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
root.addHandler(handler)

# カードリーダー取得
reader = get_reader()
# カードに接続する
connection = connect_card(reader)

# 署名PIN入力(署名秘密鍵による署名をする場合は必要)
sig_pin = input("Please input the signature PIN: ")
# 券面補助PIN入力(券面情報読み取り場合は必要)
profile_pin = input("Please input the profile PIN: ")
# 認証PIN入力(認証秘密鍵による署名をする場合は必要)
auth_pin = input("Please input the authentication PIN: ")

# カードインスタンス作成
card = Card(connection)

# 認証用証明書取得
save_to_file(filename ="Auth_Cert.der", data = card.get_cert_for_auth())
# 認証用証明書CA取得
save_to_file(filename ="ca.der", data = card.get_ca_for_auth())
# 署名用証明書取得(署名PIN必要)
save_to_file(filename ="SigCert.der", data = card.get_cert_for_sign( sig_pin))
# 署名用証明書CA取得(署名PIN必要)
save_to_file(filename ="Sign_CA.der", data = card.get_ca_for_sign( sig_pin))

# 個人番号取得(券面補助PIN必要)
print(card.get_my_number(profile_pin))
# 基本4情報取得(券面補助PIN必要)
for iter in card.get_basic_info( profile_pin):
    print(iter)

# 署名秘密鍵によるファイル署名(署名PIN必要)
save_to_file(filename ="testfile.file.sig", data = card.sign_file_with_sign_key(sig_pin, "testfile.txt") )
# 認証秘密鍵によるファイル署名(認証PIN必要)
save_to_file(filename ="testfile.auth.sig", data = card.sign_file_with_auth_key(auth_pin, "testfile.txt"))

参考

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2