Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenSSLの使い方追加 #161

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

OpenSSLの使い方追加 #161

wants to merge 3 commits into from

Conversation

shoo
Copy link
Member

@shoo shoo commented May 21, 2022

まずは暗号化と複合の例を追加しました。
過去Botanの例であった以下の代わりです。

/++
AES-128-CBCによる共通鍵暗号化/復号の例です。
getCipherのファクトリ関数で「フィルター」として変換器を作成します。 $(BR)
Pipeはストリームのように、さまざまなロジックを組み合わせることができます。 $(BR)
例えばBase64デコード→AES-128-CBCでエンコード→AES-256-CBCでエンコード→Base64エンコードする…といったことも可能です。
See_Also:
- https://github.com/etcimon/botan/wiki/Pipe-and-Filter-Message-Processing
- https://github.com/etcimon/botan#recommended-algorithms
- https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57Pt3r1.pdf P13
- https://www.ipa.go.jp/security/ipg/documents/ipa-cryptrec-gl-3001-3.0.1.pdf P26, P37
+/
unittest
{
// importはbotan.allでだいたいのものがimportできます。
// (allという割に全部じゃないので、たまにこれだけだとサンプルが動きません)
// そういう時はgitリポジトリを丸ごとcloneしてgrepかけるのが捜しやすいです(力技)。
import botan.all;
// AES共通鍵と初期化ベクトル(IV)の生成
auto key = SymmetricKey("9F86D081884C7D659A2FEAA0C55AD015");
auto iv = InitializationVector("A3BF4F1B2B0B822CD15D6C15B0F00A08");
// 暗号化
auto encoder = Pipe(getCipher("AES-128/CBC", key, iv, ENCRYPTION));
encoder.startMsg();
encoder.write("TEST");
encoder.endMsg();
auto encrypted = encoder.readAll();
// 復号
auto decoder = Pipe(getCipher("AES-128/CBC", key, iv, DECRYPTION));
decoder.startMsg();
decoder.write(encrypted);
decoder.endMsg();
auto decrypted = decoder.readAll();
// 元のデータに復元される
assert(cast(const char[])decrypted[] == "TEST");
}

@lempiji
Copy link
Member

lempiji commented Sep 17, 2022

3.2.2まで対応進んでいるのでちょっと更新版考えたいですね。バージョン上げるだけでいけそうですかね?
https://code.dlang.org/packages/openssl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants