1 / 16

JAVA Cryptography

JAVA Cryptography. AI &HC I LAB 김 성 현. A BigInteger. - 자바 1.1 은 java.math.BigInteger 를 도입 - 암호화 알고리즘 계산에 사용되는 Integer 와 단위 계산에 사용 - 계산 속도를 최적화 할 수 있는 클래스 제공. public BigInteger(int bitLength, int certainty, Random rnd) int keyLength = 2048; int certainty = 16;

kirra
Download Presentation

JAVA Cryptography

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JAVACryptography AI &HC I LAB 김 성 현

  2. A BigInteger - 자바 1.1은 java.math.BigInteger를 도입 - 암호화 알고리즘 계산에 사용되는 Integer와 단위 계산에 사용 - 계산 속도를 최적화 할 수 있는 클래스 제공

  3. public BigInteger(int bitLength, int certainty, Random rnd) int keyLength = 2048; int certainty = 16; SecureRandom sr = new SecureRandom(); BigInteger p = new BigInteger(keyLength, certainty, sr); public BigInteger(int numBits, Random rndSrc) BigInteger g = new BigInteger(keyLength-1, sr); BigInteger x = new BigInteger(keyLength-1, sr); BigInteger y = g.modPow(x, p); public BigInteger(byte[] val); public BigInteger(int signum, byte[] magnitude); BigInteger m = new BigInteger(1, messageBytes); public byte[] toByteArray();

  4. protected byte[] getBytes(BigInteger big) { byte[] bigBytes = big.toByteArray(); if ((big.bitLength() % 8) !=0) { return bigBytes; } else { byte[] smallerBytes = new byte[big.bitLength() / 8]; system.arraycopy(bigBytes, 1, smallerBytes, 0, smallerBytes.length); return smallerBytes; } }

  5. B Base64

  6. base64 digits input bytes 6 5 4 3 2 1 6 5 4 3 2 1 6 5 4 3 2 1 6 5 4 3 2 1 8 7 6 5 4 3 2 1 8 7 6 5 4 3 2 1 8 7 6 5 4 3 2 1 3개 입력 byte를 4개의 base 64 digit로 표현

  7. package oreilly.jonathan.util; public class Base64{ public static String encode(byte[] raw) { StringBuffer encoded = new StringBuffer(); for (int i = 0; i < raw.length; i += 3) { encoded.append(encodeBlock(raw, i)); } return encoded.toString(); } protected static char[] encodeBlock(byte[] raw, int offset) int block = 0; int slack = raw.length - offset -1; int end = (slack >= 2) ? 2 : slack; for (int i = 0; i <= end; i++) { byte b = raw[offset + I]; int neuter = (b < 0) ? b + 256 : b; block += neuter << (8 * (2 -i)); } char[] base64 = new char[4]; for (int i = 0; i < 4; i ++) { int sixbit = (block >>> (6 * (3 -i))) & 0x3f; base64[i] = getChar(sixbit); }

  8. if (slack < 1) base64[2] = '='; if (slack <2) base64[3] = '='; return base64; } protected static char getChar(int sixBit) { if (sixBit >=0 && sixBit <= 25) return (char)('A' + sixBit); if (sixBit >=26 && sixBit <= 51) return (char)('a' + (sixBit-26)); if (sixBit >=52 && sixBit <= 61) return (char)('0' + (sixBit-52)); if (sixBit ==62) return '+'; if (sixBit ==63) return '/'; return '?'; }

  9. public static byte[] decode(String base64) { int pad = 0; for (int i = base64.length() - 1; base64.charAt(i) == '='; I--) pad++; int length = base64.length() * 6 /8 - pad; byte[] raw = new byte[length]; int rawIndex = 0; for (int i = 0; i < base64.length(); I +=4) { int block = (getValue(base64.charAt(i)) <<18) + (getValue(base64.charAt(i + 1)) << 12) + (getValue(base64.charAt(i + 2)) << 6) + (getValue(base64.charAt(i + 3))); for (int j = 0; j < 3 && rawIndex + j <raw.length; j++) raw[rawIndex + j] = (byte) ((block >> (8 * (2 - j))) & 0xff); rawIntdex += 3; } retrun raw; }

  10. Protected static int getValue(char c) { if (c >= 'A' && c <= 'Z') return c-'A'; if (c >= 'a && c <= 'z') return c-'a' + 26; if (c >= '0' && c <= '9') return c-'0' + 52; if (c == '+' return 62; if (c == '/' return 63; if (c == '=' return 0'; return -1; } }

  11. C JAR - Java archive나 JAR 파일 생성 - JAR 파일을 생성하거나 수정에 사용

  12. Creating C:dir Volume in drive C is BUENDIA Volume Serial Number is 1929-10EE Directory of C:\f1 jdk1.2beta2\demo\GraphLayout . <DIR> 04-16-97 8:28a . .. <DIR> 04-16-97 8:28a .. EDGE~1 CLA 316 09-18-96 12:16p Edge.class GRAPH~1 CLA 3,059 09-18-96 12:16p Graph.class GRAPH~1 JAV 9,503 09-18-96 10:14a Graph.java GRAPH~2 CLA 5,986 09-18-96 12:16p GraphPanel.class NODE~1 CLA 375 09-18-96 12:16p Node.class EXAMPL~1 HTM 415 09-18-96 12:16p example1.html EXAMPL~1 HTM 241 09-18-96 12:16p example2.html EXAMPL~1 HTM 619 09-18-96 12:16p example3.html EXAMPL~1 HTM 283 09-18-96 12:16p example4.html AUDIO <DIR> 04-16-97 8:28a audio 9 file(s) 20,797 bytes 3 dir(s) 222,429,184 bytes free

  13. C:jar -cf GraphLayout.jar *.class audio C:jar -cvf GraphLayout.jar *.class audio adding: Edge.class (in=316) (out=241) (deflated 23%) adding: Graph.class (in=3059) (out=1762) (deflated 42%) adding: GraphPanel.class (in=5986) (out=3492) (deflated 41%) adding: Node.class (in=375) (out=275) (deflated 26%) adding: audio/ (in=0) (out=0) (stored 0%) adding: audio/computer.au (in=21745) (out=20105) (deflated 7%) adding: audio/drip.au (in=759) (out=764) (deflated 0%) adding: audio/gong.au (in=42068) (out=37645) (deflated 10%) -c : create -v: verbose

  14. Extrating C:jar -tvf GraphLayout.jar 948 Tue Jun 03 15:29:48 EDT 1997 META-INF/MANIFEST.MF 316 Wed Sep 18 12:16:52 EDT 1996 Edge.class 3059 Wed Sep 18 12:16:52 EDT 1997 Graph.class 5986 Wed Sep 18 12:16:54 EDT 1997 GraphPanel.class 375 Wed Sep 18 12:16:54 EDT 1997 Node.class 0 Wed Apr 16 08:28:38 EDT 1997 audio/ 21745 Wed Sep 18 12:16:56 EDT 1997 audio/computer.au 759 Wed Sep 18 12:16:56 EDT 1997 audio/drip.au 42068 Wed Sep 18 12:16:56 EDT 1997 audio/gong.au C:jar -xvf GraphLayout.jar Edge.class audio extracted: Edge.class created: audio\par extracted: audio\f1 computer.au extracted: audio\f1 drip.au extracted: audio\f1 gong.au C:jar -xvf GraphLayout.jar audio/computer.au extracted: audio\f1 computer.au -t : To view the content of JAR file -x: To extract the content of JAR file To extract the specific files from a JAR file

  15. Manifest Manifest-Version:1.0 Name: audio/computer.au Digest-Algorithms: SHA MD5 SHA-Digest: zJMcYmfFhSUPj8kdfZxKKJAXUM= MD5-Digest: 5OWrlZ4NgfWzsXuuiwxrHg== Java-Bean: True Name: Edge.class Java-Bean: True C:jar -cfm GraphLayout.jar add.mf *.class audio Name: Edge.class Java-Bean: True Digest-Algorithms: SHA MD5 SHA-Digest: sFKF74y7jL0DJQ2wuuxVgONMmEc= MD5-Digest: xRwh6TRKszKWp8qMEdiPzw==

  16. Signing signature.file=MARISIGN C:jar -tvf signedArchive.jar META-INF 288 Fri May 30 09:09:00 EDT 1997 META-INF/MANIFEST.MF 289 Wed Jun 04 15:10:54 EDT 1997 META-INF/MANIFEST.SF 1289 Wed Jun 04 15:10:54 EDT 1997 META-INF/MANIFEST.DSA

More Related