Presentation is loading. Please wait.

Presentation is loading. Please wait.

JAVA Cryptography AI &HC I LAB 김 성 현. A BigInteger - 자바 1.1 은 java.math.BigInteger 를 도입 - 암호화 알고리즘 계산에 사용되는 Integer 와 단위 계산에 사용 - 계산 속도를 최적화 할 수 있는 클래스.

Similar presentations


Presentation on theme: "JAVA Cryptography AI &HC I LAB 김 성 현. A BigInteger - 자바 1.1 은 java.math.BigInteger 를 도입 - 암호화 알고리즘 계산에 사용되는 Integer 와 단위 계산에 사용 - 계산 속도를 최적화 할 수 있는 클래스."— Presentation transcript:

1 JAVA Cryptography 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 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 : 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 > (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 EE Directory of C:\f1 jdk1.2beta2\demo\GraphLayout :28a :28a.. EDGE~1 CLA :16p Edge.class GRAPH~1 CLA 3, :16p Graph.class GRAPH~1 JAV 9, :14a Graph.java GRAPH~2 CLA 5, :16p GraphPanel.class NODE~1 CLA :16p Node.class EXAMPL~1 HTM :16p example1.html EXAMPL~1 HTM :16p example2.html EXAMPL~1 HTM :16p example3.html EXAMPL~1 HTM :16p example4.html AUDIO :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 0315:29:48EDT 1997META-INF/MANIFEST.MF 316 Wed Sep 1812:16:52EDT 1996Edge.class 3059 Wed Sep 1812:16:52EDT 1997Graph.class 5986 Wed Sep 1812:16:54EDT 1997GraphPanel.class 375 Wed Sep 1812:16:54EDT 1997Node.class 0 Wed Apr 1608:28:38EDT 1997audio/ Wed Sep 1812:16:56EDT 1997audio/computer.au 759 Wed Sep 1812:16:56EDT 1997audio/drip.au Wed Sep 1812:16:56EDT 1997audio/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 3009:09:00 EDT 1997 META-INF/MANIFEST.MF 289 Wed Jun 0415:10:54 EDT 1997 META-INF/MANIFEST.SF 1289 Wed Jun 0415:10:54 EDT 1997 META-INF/MANIFEST.DSA


Download ppt "JAVA Cryptography AI &HC I LAB 김 성 현. A BigInteger - 자바 1.1 은 java.math.BigInteger 를 도입 - 암호화 알고리즘 계산에 사용되는 Integer 와 단위 계산에 사용 - 계산 속도를 최적화 할 수 있는 클래스."

Similar presentations


Ads by Google