Created
September 18, 2019 18:27
-
-
Save toddlipcon/6c6d5acfd896f98ac8a9b47155801ecb to your computer and use it in GitHub Desktop.
This file contains 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 { | |
ASN1EncodableVector vec = new ASN1EncodableVector(); | |
vec.add(new DERTaggedObject(true, 0, new DERInteger(type))); | |
vec.add(new DERTaggedObject(true, 1, new DEROctetString(salt.getBytes("UTF-8")))); | |
return new DERSequence(vec); | |
} | |
static DERSequence makeEncryptionKey(int enctype, byte[] value) { | |
ASN1EncodableVector vec = new ASN1EncodableVector(); | |
vec.add(new DERTaggedObject(true, 0, new DERInteger(enctype))); | |
vec.add(new DERTaggedObject(true, 1, new DEROctetString(value))); | |
return new DERSequence(vec); | |
} | |
static DERSequence makeKrbKey(DERSequence salt, DERSequence key) { | |
ASN1EncodableVector vec = new ASN1EncodableVector(); | |
vec.add(new DERTaggedObject(true, 0, salt)); | |
vec.add(new DERTaggedObject(true, 1, key)); | |
return new DERSequence(vec); | |
} | |
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])) | |
});; | |
ASN1EncodableVector vec = new ASN1EncodableVector(); | |
vec.add(new DERTaggedObject(true, 0, new DERInteger(1))); | |
vec.add(new DERTaggedObject(true, 1, new DERInteger(1))); | |
vec.add(new DERTaggedObject(true, 2, new DERInteger(1))); | |
vec.add(new DERTaggedObject(true, 3, new DERInteger(1))); | |
vec.add(new DERTaggedObject(true, 4, krbKeys)); | |
System.out.println(Base64.getEncoder().encodeToString(new DERSequence(vec).getEncoded())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment