Created
September 18, 2019 19:16
-
-
Save toddlipcon/7cad0ded2266f15e79fe58f9e436c77a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Base64; | |
import org.bouncycastle.asn1.util.*; | |
import org.bouncycastle.asn1.*; | |
class Test { | |
static DERSequence makeSalt(int type, String salt) throws Exception { | |
return new DERSequence(new ASN1Encodable[]{ | |
new DERTaggedObject(true, 0, new DERInteger(type)), | |
new DERTaggedObject(true, 1, new DEROctetString(salt.getBytes("UTF-8"))) | |
}); | |
} | |
static DERSequence makeEncryptionKey(int enctype, byte[] value) { | |
return new DERSequence(new ASN1Encodable[]{ | |
new DERTaggedObject(true, 0, new DERInteger(enctype)), | |
new DERTaggedObject(true, 1, new DEROctetString(value)) | |
}); | |
} | |
static DERSequence makeKrbKey(DERSequence salt, DERSequence key) { | |
return new DERSequence(new ASN1Encodable[]{ | |
new DERTaggedObject(true, 0, salt), | |
new DERTaggedObject(true, 1, key) | |
}); | |
} | |
public static void main(String[] args) throws Exception { | |
DERSequence krbKeys = new DERSequence(new ASN1Encodable[]{ | |
makeKrbKey(makeSalt(4, "foo"), makeEncryptionKey(17, new byte[16])), | |
makeKrbKey(makeSalt(4, "foo"), makeEncryptionKey(18, new byte[32])) | |
});; | |
DERSequence krbKeySet = new DERSequence(new ASN1Encodable[]{ | |
new DERTaggedObject(true, 0, new DERInteger(1)), | |
new DERTaggedObject(true, 1, new DERInteger(1)), | |
new DERTaggedObject(true, 2, new DERInteger(1)), | |
new DERTaggedObject(true, 3, new DERInteger(1)), | |
new DERTaggedObject(true, 4, krbKeys) | |
}); | |
System.out.println(Base64.getEncoder().encodeToString(krbKeySet.getEncoded())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment