PageRenderTime 17ms CodeModel.GetById 9ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/extern/spongycastle/pkix/src/main/java/org/spongycastle/operator/bc/AESUtil.java

https://gitlab.com/vizilo/fdroidclient
Java | 34 lines | 30 code | 4 blank | 0 comment | 8 complexity | 482536ce39187a8dcb71f640d323dcb3 MD5 | raw file
 1package org.spongycastle.operator.bc;
 2
 3import org.spongycastle.asn1.ASN1ObjectIdentifier;
 4import org.spongycastle.asn1.nist.NISTObjectIdentifiers;
 5import org.spongycastle.asn1.x509.AlgorithmIdentifier;
 6import org.spongycastle.crypto.params.KeyParameter;
 7
 8class AESUtil
 9{
10    static AlgorithmIdentifier determineKeyEncAlg(KeyParameter key)
11    {
12        int length = key.getKey().length * 8;
13        ASN1ObjectIdentifier wrapOid;
14
15        if (length == 128)
16        {
17            wrapOid = NISTObjectIdentifiers.id_aes128_wrap;
18        }
19        else if (length == 192)
20        {
21            wrapOid = NISTObjectIdentifiers.id_aes192_wrap;
22        }
23        else if (length == 256)
24        {
25            wrapOid = NISTObjectIdentifiers.id_aes256_wrap;
26        }
27        else
28        {
29            throw new IllegalArgumentException("illegal keysize in AES");
30        }
31
32        return new AlgorithmIdentifier(wrapOid); // parameters absent
33    }
34}