0
0

JavaでAESWrapアルゴリズムを試してみる

Posted at

今更ながらJavaでAESWrapアルゴリズムを試してみた

		// Java Version
		System.out.println("Java Version: " + System.getProperty("java.version"));

		// キーを初期化(例として16バイトの0で初期化)
		byte[] keyBytes = new byte[16];
		SecretKey key = new SecretKeySpec(keyBytes, "AES");

		// Cipherインスタンスを初期化
		Cipher cipher = Cipher.getInstance("AESWrap");

		// アルゴリズムの確認
		System.out.println("Algorithm: " + cipher.getAlgorithm());

		// 両方のCipherインスタンスで同じキーを使用して暗号化し、結果を比較
		cipher.init(Cipher.WRAP_MODE, key);

        // テスト用のデータを乱数で生成
        SecureRandom random = new SecureRandom();
        byte[] toWrap = new byte[8]; // 8バイトのデータ
        random.nextBytes(toWrap);
		byte[] wrapped = cipher.wrap(new SecretKeySpec(toWrap, "AES"));

		// wrapped と値を16進数の文字列として出力
        System.out.println("Wrapped: " + bytesToHex(wrapped));
0
0
1

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
0
0