Skip to content

Instantly share code, notes, and snippets.

View kjunichi's full-sized avatar

Junichi Kajiwara kjunichi

View GitHub Profile
@kjunichi
kjunichi / 20240912.md
Last active September 12, 2024 03:00
xmlCipher.setKEK(inputKey);
xmlCipher.doFinal(encryptedDataElement.getOwnerDocument(), encryptedDataElement, false);
public static void register(String id, Algorithm algorithm) {
        JavaUtils.checkRegisterPermission();
        algorithmsMap.put(id, algorithm);

EntraID

SAMLアサーションを暗号化するとデフォルトの署名設定だと署名が付かない。 すくなくとも平文のXMLにはSignatureタグが無かった。

@kjunichi
kjunichi / 20240910.md
Last active September 10, 2024 06:24

JavaでのXML署名

  1. Detached 署名  XML署名と対象文書が独立している形式
  2. Enveloped 署名  対象文書の中にXML署名を格納した形式
  3. Enveloping 署名  XML署名の中に対象文書を格納した形式

Azure ADでの設定

暗号関連

カウンターモード

パディングが不要

AES-256-GCMのIVの長さ

12バイトらしい。 カウンターの4バイトは含めない模様。

@kjunichi
kjunichi / gist:1e02db8d88d348dcd6f8e8b58673cfff
Last active September 9, 2024 04:53
GCMな暗号に関しての調査メモ

ruby-saml/lib/onelogin/ruby-saml /utils.rb

JavaでCipherを使う場合、GCMのtagは暗号文に含まれる模様

復号に必要なパラメータ

iv_len, text_len, tag_len = auth_cipher.iv_len, cipher_text.length, 16

iv

RSA/ECB/OAEPWITHSHA-1ANDMGF1PADDING

byte[] privateDer = Base64.getDecoder().decode(privateKey);
PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(privateDer);        
Cipher decrypter = Cipher.getInstance("RSA/ECB/OAEPWITHSHA-1ANDMGF1PADDING");
decrypter.init(Cipher.DECRYPT_MODE, privatekey);
byte[] decrypt = decrypter.doFinal(Base64.getDecoder().decode(encryptedKey)); 
@kjunichi
kjunichi / 20240825.md
Last active September 12, 2024 01:52

XMLの暗号化のアルゴリズムの種類

以下ので全てなのか?

@kjunichi
kjunichi / Main.java
Created August 20, 2024 09:00
SAMLValidation
import java.nio.file.Paths;
import java.security.Key;
import java.security.KeyException;
import java.security.PublicKey;
import java.security.Signature;
import java.security.cert.X509CRL;
import java.security.cert.X509Certificate;
import java.util.List;
import java.util.Iterator;
import java.nio.file.Paths;
import java.security.Key;
import java.security.KeyException;
import java.security.PublicKey;
import java.security.cert.X509CRL;
import java.security.cert.X509Certificate;
import java.util.List;
import java.util.Iterator;
import javax.xml.crypto.AlgorithmMethod;

JavaでXMLファイルを読み込む

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(Paths.get("test.xml").toFile());