๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ๋ฐœ/JAVA

[JAVA] ๋Œ€์นญํ‚ค ์•”ํ˜ธํ™” ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํ‚ค ์ œํ•œ ์˜ค๋ฅ˜ ํ•ด๊ฒฐ : Illegal key size

by ynzu๐Ÿค 2022. 1. 26.
๋ฐ˜์‘ํ˜•

 

๊ฐœ๋ฐœ ์ค‘ ๋Œ€์นญํ‚ค๋กœ ์•”ํ˜ธํ™”ํ•ด์•ผํ•  ์ƒํ™ฉ์ด ์ƒ๊ฒผ๋Š”๋ฐ(DESede/CBC, DES/CBC, AES/CBC ๋“ฑ์˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ด์šฉ), 192 ํ˜น์€ 256 bit์˜ ๋Œ€์นญํ‚ค๋ฅผ ์ด์šฉํ•˜์—ฌ ์•”ํ˜ธํ™”๋ฅผ ํ•  ๊ฒฝ์šฐ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‹ค.

java.security.InvalidKeyException: Illegal key size

์›์ธ์„ ์ฐพ์•„๋ณด๋‹ˆ Java๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ JCE ์ •์ฑ…์„ ์ œ๊ณตํ•˜๋Š”๋ฐ ์ด ์ •์ฑ…์€ ๋ฏธ๊ตญ์˜ ์ •์ฑ…์— ๋”ฐ๋ผ 128 bit๋กœ ํ‚ค ๊ธธ์ด๊ฐ€ ์ œํ•œ๋˜์–ด ์žˆ์–ด์„œ ์ด๋ฅผ ์ดˆ๊ณผํ•˜๋Š” ๊ฒฝ์šฐ์—” ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋Š” ๊ฒƒ ์ด๋‹ค.

์ด ์ •์ฑ…์€  <JAVA_HOME>/jre/lib/security/local_policy.jar์˜ default_local.policy ํŒŒ์ผ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์ •์ฑ… ๋‚ด์šฉ์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

// Some countries have import limits on crypto strength. This policy file
// is worldwide importable.

grant {
    permission javax.crypto.CryptoPermission "DES", 64;
    permission javax.crypto.CryptoPermission "DESede", *;
    permission javax.crypto.CryptoPermission "RC2", 128, 
                                     "javax.crypto.spec.RC2ParameterSpec", 128;
    permission javax.crypto.CryptoPermission "RC4", 128;
    permission javax.crypto.CryptoPermission "RC5", 128, 
          "javax.crypto.spec.RC5ParameterSpec", *, 12, *;
    permission javax.crypto.CryptoPermission "RSA", *;
    permission javax.crypto.CryptoPermission *, 128;
};

 

Oracle์—์„œ๋Š” 128 bit๋ฅผ ์ดˆ๊ณผํ•˜๋Š” ํ‚ค๋ฅผ ์‚ฌ์šฉํ•˜๊ณ ์ž ํ•˜๋Š” ์‚ฌ์šฉ์ž๋ฅผ ์œ„ํ•ด JCE Unlimited Strength ์ •์ฑ… ํŒŒ์ผ์„ ์ œ๊ณตํ•œ๋‹ค.
๋”ฐ๋ผ์„œ ์‚ฌ์šฉ์ค‘์ธ JAVA ๋ฒ„์ „์— ๋งž์ถฐ ์ •์ฑ… ํŒŒ์ผ์„ ๋‹ค์šด๋ฐ›์•„ ๊ต์ฒด ํ•ด์ฃผ๋ฉด ๋œ๋‹ค!

๋‹ค์šด๋ฐ›์€ local_policy.jar, US_export_policy.jar ํŒŒ์ผ์„ <JAVA_HOME>/jre/lib/security/ ๋””๋ ‰ํ† ๋ฆฌ๋กœ ์˜ฎ๊ธด๋‹ค. 

๊ธฐ์กด ์ •์ฑ… ํŒŒ์ผ์€ ์‚ญ์ œํ•ด๋„ ๋˜๊ณ , ๋ฎ์–ด์“ฐ๊ธฐํ•ด๋„ ๋œ๋‹ค. ์—ฌ๊ธฐ๊นŒ์ง€ ํ•˜๋ฉด JCE๋กœ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ์•”ํ˜ธํ™”์˜ ํ‚ค ๊ธธ์ด ์ œํ•œ์ด ํ•ด์ œ๋˜์–ด 128 bit๋ฅผ ์ดˆ๊ณผํ•˜๋Š” ๋Œ€์นญํ‚ค ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.


JDK 8u151 ์ด์ƒ ๋ฒ„์ „์—์„œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ๋‘๊ฐœ์˜ ๋””๋ ‰ํ† ๋ฆฌ๋กœ ๋‚˜๋‰˜์–ด์ ธ ์žˆ๊ณ ,  JCE ๋‹ค์šด๋กœ๋“œ ์—†์ด /jre/lib/security/java.security ํŒŒ์ผ์— crypto.policy=unlimited ์˜ต์…˜ ์ง€์ • ์‹œ ๋ฐ”๋กœ ์‚ฌ์šฉ๊ฐ€๋Šฅํ•˜๋‹ค.

  • <JAVA_HOME>/jre/lib/security/policy/limited
  • <JAVA_HOME>/jre/lib/security/policy/unlimited

 

 

728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€