В одной из моих документов сказано:
Сгенерируйте закрытый и открытый ключи, используя параметры Диффи-Хеллмана ('p' и 'g').Результатом являются 'Pub_key' и 'Priv_key' (1024-бит / 128 байт).
, где P и G дают следующее:
Diffie-Hellman-Параметры: (1024 бит) Простое (p): e5: 16: e4: 3e: 54: 57: b2: f6: 6f: 6c: a3: 67: b3: 35: ea: d8: 31: 99: 39: fa: 4d: f6: c1: b7: f8: 6e: 73: e9: 22: a6: d1: 93: 93: 25: 5e: 41: 90: 96: 66: 81: 74: e3: 5c: 81: 8a: 66: 11: 7f: 79: 9e: 86: 66: c8: 05: 0e: e4: 36: f9: 80: 13: 51: 60: 6c: 55: d4: 5f: ab: a0: 3f: 39: e2: 92: 3b: a9: 26: a9: cd: 75: d4: bd: bc: a9: de: 78: b6: 2a: 9b: 84: 7a: 78: 1c: 69: 2c: 06: 3e: aa: cb: 43: a3: 96: f0: 1d: 12: 1d: 04: 27: 55: d0: b7: c0: b2: df: a8: b4: 98: a5: 7e: 4d: 90: c3: 0c: a0: 49: a7: ac: 2b: 7f: 73
генератор (г): 5 (0x5)
Пример данных, приведенных в документации об открытом ключевыглядит следующим образом:
85: f0: 4d: d0: 03: 45: 64: 2a: d1: 2b: 65: bd: 1a: 7c: 38: 72: 8b: ff: 0b:8e: 28: 1d: db: 6a: c4: f2: 73: 9e: 82: a0: 21: 45: da: ab: f2: 3d: 17: 3c: 93: 39: 13: b1: f8: 44:05:97: 10: e9: 12: 55: 91: 56: 9d: e4: 27: ea: e1: d2: 69: ac: cb: fa: 33: 05: 06: 9d: eb: 76: 22:d1: да: 3a: D9: 82: 0d: 11: шд: 24: ФД: сс: е5: 38: 1d: 2d: f9: 9b: да: 31: 43: 94: 73: 8d: fc: be: 21: 0e: ae: 24: 7b: 13: 03: e7: 92: 97: ff: 74: 6c: d9: 19: e1: 89: f6: a5: 77: 6e:6e: cc: 24: c8: 90: 0d: e0: f3: 8f: 15: 90: 72: de
Однако, когда я пытаюсь самостоятельно использовать Java для генерации открытого ключа DH, используяпараметр, я получаю что-то вроде этого:
30: 82: 01: 24: 30: 81: 99: 06: 09: 2A: 86: 48: 86: F7: 0D: 01: 03: 01: 30: 81: 8B: 02: 81: 81: 00: Е5: 16: Е4: 3E: 54: 57: В2: F6: 6F: 6C: А3: 67: B3: 35: ЕА: D8: 31: 99: 39: FA: 4D: F6: C1: В7: F8: 6E: 73: Е9: 22: A6: D1: 93: 93: 25: 5E: 41: 90: 96: 66: 81: 74: E3: 5C: 81: 8А: 66: 11: 7F: 79: 9E: 86: 66: С8: 05: 0E: Е4: 36: F9: 80: 13: 51: 60: 6C: 55: D4: 5F: АВ: A0: 3F: 39: Е2: 92: 3B: A9: 26: А9: CD: 75: D4: BD: БК: А9: DE: 78: B6: 2A: 9В: 84: 7A: 78: 1C: 69: 2C: 06: 3E: АА: СВ: 43: А3: 96: F0: 1D: 12: 1D: 04: 27: 55: D0: В7: С0: В2: ДФ: A8: В4: 98: А5: 7E: 4D: 90: С3: 0C: A0: 49: A7: AC: 2B: 7F: 73: 02: 01: 05: 02: 02: 02: 00: 03: 81: 85: 00: 02: 81: 81: 00: А9: АФ: 1C: F3: 45: 77: 8C: BA: БК: 32: 59: 52: 7В: ЕА: 90: 80: 74: 9A: 1D: A7: 01: D4: С4: 10: 74: 4C: 6E: Е9: 35: 36: 49: 6D: 0D: 03: F5: 2D: EC: FA: С5: CE: CD: С9: 23: D3: F5: 2F: С2: Е0: 3E: 54: 3C: A1: 20: 6B: ED: CC: 6C: 1F: 52: 26: 7D: CD: Е7: 0D: 14: F8: 34: В0: 36: В7: F9: FD:AC: 97: 4C: С0: 7D: 50: 7E: DC: Е0: D4: 62: 52: 27: 7В: FE: 0B: 16: 62: 34: 81: 2A: Е1: 8B: 6A: 54:ЕЕ: 55: 6D: С3: D0: F4: 89: A1: Е8: 11: F0: 67: 3E: 17: AB: BF: С3: 6C: В7: 37: 51: 29: 36: 45: BA:26: BF: CB: 90: AE: A7
Как вы можете видеть, это намного длиннее ...
Вот часть кода, которая у меня есть
import java.math.BigInteger;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import javax.crypto.KeyAgreement;
import javax.crypto.spec.DHParameterSpec;
public class DHKeyAgreement {
// The 1024 bit Diffie-Hellman modulus values used by SKIP
private static final byte skip1024ModulusBytes[] = {(byte) 0xe5, (byte) 0x16, (byte) 0xe4,
(byte) 0x3e, (byte) 0x54, (byte) 0x57, (byte) 0xb2, (byte) 0xf6, (byte) 0x6f, (byte) 0x6c,
(byte) 0xa3, (byte) 0x67, (byte) 0xb3, (byte) 0x35, (byte) 0xea, (byte) 0xd8, (byte) 0x31,
(byte) 0x99, (byte) 0x39, (byte) 0xfa, (byte) 0x4d, (byte) 0xf6, (byte) 0xc1, (byte) 0xb7,
(byte) 0xf8, (byte) 0x6e, (byte) 0x73, (byte) 0xe9, (byte) 0x22, (byte) 0xa6, (byte) 0xd1,
(byte) 0x93, (byte) 0x93, (byte) 0x25, (byte) 0x5e, (byte) 0x41, (byte) 0x90, (byte) 0x96,
(byte) 0x66, (byte) 0x81, (byte) 0x74, (byte) 0xe3, (byte) 0x5c, (byte) 0x81, (byte) 0x8a,
(byte) 0x66, (byte) 0x11, (byte) 0x7f, (byte) 0x79, (byte) 0x9e, (byte) 0x86, (byte) 0x66,
(byte) 0xc8, (byte) 0x05, (byte) 0x0e, (byte) 0xe4, (byte) 0x36, (byte) 0xf9, (byte) 0x80,
(byte) 0x13, (byte) 0x51, (byte) 0x60, (byte) 0x6c, (byte) 0x55, (byte) 0xd4, (byte) 0x5f,
(byte) 0xab, (byte) 0xa0, (byte) 0x3f, (byte) 0x39, (byte) 0xe2, (byte) 0x92, (byte) 0x3b,
(byte) 0xa9, (byte) 0x26, (byte) 0xa9, (byte) 0xcd, (byte) 0x75, (byte) 0xd4, (byte) 0xbd,
(byte) 0xbc, (byte) 0xa9, (byte) 0xde, (byte) 0x78, (byte) 0xb6, (byte) 0x2a, (byte) 0x9b,
(byte) 0x84, (byte) 0x7a, (byte) 0x78, (byte) 0x1c, (byte) 0x69, (byte) 0x2c, (byte) 0x06,
(byte) 0x3e, (byte) 0xaa, (byte) 0xcb, (byte) 0x43, (byte) 0xa3, (byte) 0x96, (byte) 0xf0,
(byte) 0x1d, (byte) 0x12, (byte) 0x1d, (byte) 0x04, (byte) 0x27, (byte) 0x55, (byte) 0xd0,
(byte) 0xb7, (byte) 0xc0, (byte) 0xb2, (byte) 0xdf, (byte) 0xa8, (byte) 0xb4, (byte) 0x98,
(byte) 0xa5, (byte) 0x7e, (byte) 0x4d, (byte) 0x90, (byte) 0xc3, (byte) 0x0c, (byte) 0xa0,
(byte) 0x49, (byte) 0xa7, (byte) 0xac, (byte) 0x2b, (byte) 0x7f, (byte) 0x73};
// The SKIP 1024 bit modulus
private static final BigInteger skip1024Modulus = new BigInteger(1, skip1024ModulusBytes);
// The base used with the SKIP 1024 bit modulus
private static final BigInteger skip1024Base = BigInteger.valueOf(5);
public static void main(String[] args) throws Exception {
DHParameterSpec dhSkipParamSpec;
dhSkipParamSpec = new DHParameterSpec(skip1024Modulus, skip1024Base);
System.out.println("ALICE: Generate DH keypair ...");
KeyPairGenerator aliceKpairGen = KeyPairGenerator.getInstance("DH");
aliceKpairGen.initialize(dhSkipParamSpec);
KeyPair aliceKpair = aliceKpairGen.generateKeyPair();
System.out.println("ALICE: Initialization ...");
KeyAgreement aliceKeyAgree = KeyAgreement.getInstance("DH");
aliceKeyAgree.init(aliceKpair.getPrivate());
// Alice encodes her public key, and sends it over to Bob.
byte[] alicePubKeyEnc = aliceKpair.getPublic().getEncoded();
byte[] alicePrivKeyEnc = aliceKpair.getPrivate().getEncoded();
System.out.println("ALICE public key: " + toHexString(alicePubKeyEnc));
System.out.println("Alice private key: " + toHexString(alicePrivKeyEnc));
}
/*
* Converts a byte to hex digit and writes to the supplied buffer
*/
private static void byte2hex(byte b, StringBuffer buf) {
char[] hexChars =
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
int high = ((b & 0xf0) >> 4);
int low = (b & 0x0f);
buf.append(hexChars[high]);
buf.append(hexChars[low]);
}
/*
* Converts a byte array to hex string
*/
private static String toHexString(byte[] block) {
StringBuffer buf = new StringBuffer();
int len = block.length;
for (int i = 0; i < len; i++) {
byte2hex(block[i], buf);
if (i < len - 1) {
buf.append(":");
}
}
return buf.toString();
}
}
Я что-то недопонимаю или документация неверна?