/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

  1. package org.spongycastle.operator.bc;
  2. import org.spongycastle.asn1.ASN1ObjectIdentifier;
  3. import org.spongycastle.asn1.nist.NISTObjectIdentifiers;
  4. import org.spongycastle.asn1.x509.AlgorithmIdentifier;
  5. import org.spongycastle.crypto.params.KeyParameter;
  6. class AESUtil
  7. {
  8. static AlgorithmIdentifier determineKeyEncAlg(KeyParameter key)
  9. {
  10. int length = key.getKey().length * 8;
  11. ASN1ObjectIdentifier wrapOid;
  12. if (length == 128)
  13. {
  14. wrapOid = NISTObjectIdentifiers.id_aes128_wrap;
  15. }
  16. else if (length == 192)
  17. {
  18. wrapOid = NISTObjectIdentifiers.id_aes192_wrap;
  19. }
  20. else if (length == 256)
  21. {
  22. wrapOid = NISTObjectIdentifiers.id_aes256_wrap;
  23. }
  24. else
  25. {
  26. throw new IllegalArgumentException("illegal keysize in AES");
  27. }
  28. return new AlgorithmIdentifier(wrapOid); // parameters absent
  29. }
  30. }