# .NET開発者用セットアップ

## .NET SDK

Keeper .NET SDKは、Keeperパスワードマネージャーのボルトおよび管理機能に包括的にアクセスできる開発者向けライブラリです。最新の.NETアプリケーション向けに設計されており、エンタープライズ向けパスワード管理、特権アクセス管理、シークレット管理をシームレスに統合できます。

### 主な機能

* セキュアなボルトアクセスと同期
* レコードのライフサイクル管理
* エンタープライズユーザーおよびチーム管理
* パスワードの自動ローテーション
* フォルダおよび共有フォルダの管理
* 添付ファイルの操作
* BreachWatchとの連携
* クロスプラットフォーム対応 (Windows、macOS、Linux)

### インストール方法

NuGetパッケージマネージャーから

```bash
dotnet add package Keeper.Sdk
```

.csproj参照で追加する場合

```xml
<PackageReference Include="Keeper.Sdk" Version="1.1.2" />
```

### SDKコンポーネント

#### コアSDKライブラリ

Keeperのボルトや管理機能をプログラムから操作できるようにします。

* ソースコード: [KeeperSdk (GitHub)](https://github.com/Keeper-Security/keeper-sdk-dotnet/tree/master/KeeperSdk)
* はじめに: [KeeperSdk README](https://github.com/Keeper-Security/keeper-sdk-dotnet/blob/master/KeeperSdk/README.md)
* ドキュメント: [KeeperSdkドキュメント](https://docs.keeper.io/jp/keeperpam/commander-sdk/keeper-commander-sdks/sdk-command-reference)
* NuGetパッケージ: [Keeper.Sdk](https://www.nuget.org/packages/KeeperSdk/)

#### **DotNetコマンダーCLI**

ボルト管理用の高機能コマンドラインアプリケーションです。

* ソースコード: [Commander (GitHub)](https://github.com/Keeper-Security/keeper-sdk-dotnet/tree/master/Commander)
* はじめに: [Commander README](https://github.com/Keeper-Security/keeper-sdk-dotnet/blob/master/Commander/README.md)
* ドキュメント: [KeeperSdkドキュメント](https://docs.keeper.io/jp/keeperpam/commander-sdk/keeper-commander-sdks/sdk-command-reference)
* 主な機能: 対話型シェル、バッチ操作、エンタープライズ管理

#### **PowerCommanderモジュール**

自動化やスクリプト処理向けのPowerShellモジュールです。

* インストール: `Install-Module -Name PowerCommander`
* ソースコード: [PowerCommander (GitHub)](https://github.com/Keeper-Security/keeper-sdk-dotnet/tree/master/PowerCommander)
* はじめに: [PowerCommander README](https://github.com/Keeper-Security/keeper-sdk-dotnet/blob/master/PowerCommander/README.md)
* ドキュメント: [KeeperSdkドキュメント](https://docs.keeper.io/jp/keeperpam/commander-sdk/keeper-commander-sdks/sdk-command-reference)

### 開発者向け要件

#### 対応フレームワーク

* **.NET 8.0**: 最新の.NETバージョンで、パフォーマンスが向上
* **.NET Standard 2.0**: .NET Frameworkおよび.NET Coreとの高い互換性

#### 対応プラットフォーム

* Windows (10以降、Server 2019以降)
* macOS (11.0以降)
* Linux (Ubuntu 20.04以降、RHEL 8以降)

#### 開発環境の要件

* [.NET 8.0 SDK](https://dotnet.microsoft.com/download)以上
* Visual Studio 2022、VS Code、JetBrains Rider (推奨)
* Keeper Securityアカウント (登録は[こちら](https://keepersecurity.com/))

#### ソース統合

.NETコードにKeeperSDKライブラリを統合する場合は、[こちらのGithubページ](https://github.com/Keeper-Security/keeper-sdk-dotnet/tree/release/KeeperSdk)にあるソースコードをご利用ください。

## APIドキュメント

包括的なAPIリファレンスドキュメントについては[こちらのページ](https://keeper-security.github.io/gitbook-keeper-sdk/CSharp/html/R_Project_Documentation.htm)をご覧ください。

#### 主な名前空間

| 名前空間                                                                                                                                  | 説明                      |
| ------------------------------------------------------------------------------------------------------------------------------------- | ----------------------- |
| [KeeperSecurity.Authentication](https://keeper-security.github.io/gitbook-keeper-sdk/CSharp/html/N_KeeperSecurity_Authentication.htm) | 認証、2FA、デバイス承認、SSO       |
| [KeeperSecurity.Vault](https://keeper-security.github.io/gitbook-keeper-sdk/CSharp/html/N_KeeperSecurity_Vault.htm)                   | ボルト操作、レコード、フォルダ、添付ファイル  |
| [KeeperSecurity.Enterprise](https://keeper-security.github.io/gitbook-keeper-sdk/CSharp/html/N_KeeperSecurity_Enterprise.htm)         | エンタープライズ管理、ユーザー、チーム、ロール |
| [KeeperSecurity.Configuration](https://keeper-security.github.io/gitbook-keeper-sdk/CSharp/html/N_KeeperSecurity_Configuration.htm)   | 構成情報の保存と管理              |

### コア機能

#### 認証

* **AuthSync**: 同期型の認証フロー
* **マスターパスワード**: 標準的なKeeper認証方式
* **二要素認証 (2FA)**: TOTP、SMS、プッシュ通知に対応
* **デバイス承認**: メールおよび管理者による承認フロー
* **SSO統合**: エンタープライズ向けシングルサインオン
* **生体認証**: WebAuthn/FIDO2対応

#### ボルト操作

* **レコード**: レコードの作成、読み取り、更新、削除
* **タイプ付きレコード**: すべてのKeeperレコードタイプおよびカスタムタイプに対応
* **添付ファイル**: ファイルのアップロードおよびダウンロード
* **フォルダ**: 階層構造によるレコード整理
* **共有フォルダ**: チームでの共同管理と権限設定
* **検索**: タイトル、URL、カスタムフィールドによるレコード検索

#### エンタープライズ管理

* **ユーザー管理**: エンタープライズユーザーの作成、変更、削除
* **チーム管理**: ユーザーをチーム単位で整理
* **ロールベースアクセス**: ロールと権限の管理
* **監査ログ**: 監査履歴の取得と分析
* **デバイス管理**: デバイスの承認と管理
* **マネージドカンパニー**: MSP向けのマルチテナント運用

#### セキュリティ機能

* **エンドツーエンド暗号化**: ゼロ知識アーキテクチャ
* **デバイストークン管理**: セキュアな永続セッション
* **BreachWatch**: 流出した認証情報の監視
* **パスワードレポート**: セキュリティおよびコンプライアンスレポートの生成

### リソース

#### ドキュメント

* [メインリポジトリ](https://github.com/Keeper-Security/keeper-sdk-dotnet)
* [SDKドキュメント](https://github.com/Keeper-Security/keeper-sdk-dotnet/blob/master/KeeperSdk/README.md)
* [コマンダーCLIガイド](https://github.com/Keeper-Security/keeper-sdk-dotnet/blob/master/Commander/README.md)
* [PowerCommanderガイド](https://github.com/Keeper-Security/keeper-sdk-dotnet/blob/master/PowerCommander/README.md)
* [サンプルアプリケーション](https://github.com/Keeper-Security/keeper-sdk-dotnet/blob/master/Sample/README.md)

### サポート

#### ヘルプの入手

* **メール**: <commander@keepersecurity.com>
* **GitHub Issues**: [バグの報告や機能リクエスト](https://github.com/Keeper-Security/keeper-sdk-dotnet/issues)
* **ウェブサイト**: [keepersecurity.com](https://keepersecurity.com)

#### エンタープライズサポート

エンタープライズ向けサポート、カスタム統合、または技術支援については、<commander@keepersecurity.com> までお問い合わせください。

### サンプルコード

SDK機能の実装例については、[こちらのGithubページ](https://github.com/Keeper-Security/keeper-sdk-dotnet/tree/master/Sample)のサンプルアプリケーションを参照してください。

.NETコマンダーCLI[サンプルアプリ](https://github.com/Keeper-Security/keeper-sdk-dotnet/tree/release/Commander)には、ログイン、二要素認証、ボルトの読み込みと復号化、パスワードの更新など、基本的な操作が含まれています。

以下の例では、コンソール入力を処理するために `InputManager` クラスを使用しています。実装については[こちらのGithubページ](https://github.com/Keeper-Security/keeper-sdk-dotnet/blob/master/Cli/InputManager.cs)でご確認ください。

#### 基本の認証とボルトへのアクセス

```csharp
using System;
using System.Linq;
using System.Threading.Tasks;
using Cli;
using KeeperSecurity.Authentication;
using KeeperSecurity.Authentication.Sync;
using KeeperSecurity.Configuration;
using KeeperSecurity.Vault;

// 構成ストレージを初期化
var configStorage = new JsonConfigurationStorage("config.json");
var inputManager = new SimpleInputManager();

// AuthSyncを使用してKeeperにログイン
var auth = new AuthSync(configStorage);
await Utils.LoginToKeeper(auth, inputManager, "your-email@company.com");

// ボルトインスタンスを作成して同期
var vault = new VaultOnline(auth);
await vault.SyncDown();

// レコードにアクセス
Console.WriteLine($"Your vault has {vault.RecordCount} records.");
```

#### レコードの新規作成

```csharp
// タイプ付きログインレコードを作成
var loginRecord = new TypedRecordFacade<LoginRecordType>();
loginRecord.Fields.Login = "admin@myapp.com";
loginRecord.Fields.Password = "SecurePassword123!";
loginRecord.Fields.Url = "https://myapp.com";

var typedRecord = loginRecord.TypedRecord;
typedRecord.Title = "My Application";
typedRecord.Notes = "Production credentials";

var createdRecord = await vault.CreateRecord(typedRecord);
Console.WriteLine($"Record created with UID: {createdRecord.Uid}");
```

#### パスワード変更

```csharp
// パスワードを検索して更新
var record = vault.KeeperRecords
    .FirstOrDefault(x => x.Title == "Database");

if (record is PasswordRecord passwordRecord)
{
    passwordRecord.Password = "NewSecurePassword123!";
    await vault.UpdateRecord(passwordRecord);
    Console.WriteLine("Password rotated successfully");
}
```

#### 添付ファイル操作

```csharp
using System.IO;
using KeeperSecurity.Commands;

// 添付ファイルのアップロード
using (var stream = File.OpenRead("config.json"))
{
    var uploadTask = new FileAttachmentUploadTask("config.json")
    {
        Title = "Configuration File",
        MimeType = "application/json"
    };
    await vault.UploadAttachment(record, uploadTask);
}

// 添付ファイルのダウンロード
var attachment = vault.RecordAttachments(record).FirstOrDefault();
if (attachment != null)
{
    using (var stream = File.Create(attachment.Title))
    {
        await vault.DownloadAttachment(record, attachment.Id, stream);
    }
}
```

#### 共有フォルダ管理

```csharp
// 共有フォルダを取得
var sharedFolder = vault.SharedFolders
    .FirstOrDefault(x => x.Name == "Team Credentials");

// ユーザーを共有フォルダに追加
await vault.PutUserToSharedFolder(
    sharedFolder.Uid,
    "user@company.com",
    UserType.User,
    new SharedFolderUserOptions
    {
        ManageRecords = true,
        ManageUsers = false
    }
);
```

#### エンタープライズユーザー管理

```csharp
using KeeperSecurity.Enterprise;

if (auth.AuthContext.IsEnterpriseAdmin)
{
    // Load enterprise data
    var enterprise = new EnterpriseData();
    var loader = new EnterpriseLoader(auth, new[] { enterprise });
    await loader.Load();
    
    // チーム作成
    var team = await enterprise.CreateTeam(new EnterpriseTeam
    {
        Name = "Engineering",
        RestrictEdit = false,
        RestrictSharing = true
    });
    
    // ユーザーをチームに作成
    await enterprise.AddUsersToTeams(
        new[] { "user@company.com" },
        new[] { team.Uid },
        Console.WriteLine
    );
}
```
