1. Trang chủ
  2. » Công Nghệ Thông Tin

Nghiên cứu mã hóa dựa trên định danh IBE và ứng dụng vào bài toán kiểm soát quyền truy cập trong hệ thống truyền hình trả tiền

103 342 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Nội dung

ĐẠI HỌC THÁI NGUYÊN TRƯỜNG ĐẠI HỌC CÔNG NGHỆ THÔNG TIN VÀ TRUYỀN THÔNG –––––––––––––––––––––––––––––––––––– NGUYỄN VÂN ANH NGHIÊN CỨU MÃ HÓA DỰA TRÊN ĐỊNH DANH – IBE VÀ ỨNG DỤNG VÀO BÀI TOÁN KIỂM SOÁT QUYỀN TRUY CẬP TRONG HỆ THỐNG TRUYỀN HÌNH TRẢ TIỀN Chuyên ngành: Khoa học máy tính Mã số: 60.48.01.01 LUẬN VĂN THẠC SĨ KHOA HỌC MÁY TÍNH Người hướng dẫn khoa học: TS PHẠM THẾ QUẾ THÁI NGUYÊN - 2013 i LỜI CẢM ƠN Trên thực tế thành công mà không gắn liền với hỗ trợ, giúp đỡ, Trong suốt thời gian từ bắt đầu học tập trường đến nay, em nhận nhiều quan tâm, giúp đỡ quý Thầy Cô Khoa sau đại học trường Đại học Công nghệ Thông tin Truyền thông – Đại học Thái Nguyên với tri thức tâm huyết để truyền đạt vốn kiến thức quý báu cho chúng em suốt thời gian học tập trường, luôn tạo điều kiện tốt cho chúng em suốt trình theo học Em xin chân thành cảm ơn quý Thầy Cô Ban lãnh đạo nhà trường! Với lòng biết ơn sâu sắc em xin gửi lời cảm ơn tới TS Phạm Thế Quế, Khoa Công nghệ Thông tin – Học viện Bưu Chính Viễn Thông, cán trực tiếp hướng dẫn khoa học cho em Thầy dành nhiều thời gian cho việc hướng dẫn em cách nghiên cứu, đọc tài liệu, cài đặt thuật toán giúp đỡ em việc xây dựng chương trình, em xin chân thành cảm ơn Thầy! Và cuối em xin bày tỏ lòng chân thành biết ơn tới lãnh đạo khoa Công nghệ Thông tin trường đại học Kinh doanh Công nghệ Hà Nội bạn bè đồng nghiệp bên cạnh lúc em khó khăn tạo điều kiện thuận lợi giúp em hoàn thành luận văn Hà Nội, ngày 20 tháng 10 năm 2013 Học viên: Nguyễn Vân Anh ii MỤC LỤC Lời cảm ơn .i Mục lục ii Danh mục bảng iii Danh mục hình iv LỜI MỞ ĐẦU .1 TỔNG QUAN VỀ HỆ MẬT MÃ KHÓA CÔNG KHAI 1.1 Tổng quan mật mã Các tiêu chí đặc trưng hệ thống mã hoá: .4 1.2 Kỹ thuật mật mã khóa công khai 1.2.1.Cấu trúc hệ thống mật mã khóa công khai .6 1.2.3 Thuật toán trao đổi khoá Diffie-Hellman .10 1.2.4 Đánh giá kỹ thuật mật mã bất đối xứng 12 1.3 Hàm băm 13 1.3.1 Xác thực thông tin 13 1.3.2 Các hàm băm bảo mật 17 1.3.3 Hàm băm MD5 19 1.4 Chữ ký số 20 1.4.1 Nguyên lý hoạt động chữ ký số: .20 1.4.2 Chuẩn chữ ký DSS 24 1.5 Quản lý khoá 28 1.5.1 Quản lý khoá công khai mật mã bất đối xứng: 28 1.5.2 Sử dụng mật mã bất đối xứng để trao đổi khóa bí mật: .30 HỆ MẬT MÃ DỰA TRÊN ĐỊNH DANH 33 2.1 Tổng quan mật mã dựa định danh 33 2.2 Mã hóa dựa thuộc tính 38 2.3 Lược đồ mã hóa dựa đinh danh ibe 43 iii 2.4 Cài đặt (THE IMPLEMENTATION) .45 iv DANH SÁCH CÁC HÌNH Trang Hình 1.1: Cấu trúc hệ thống mật mã quy ước Hình 1.2: Cấu trúc hệ thống mật mã bất đối xứng Hình 1.3: Thuật toán trao đổi khoá Diffie-Hellman 11 Hình 1.4: Xác thực thông tin dùng mật mã 15 Hình 1.5: Xác thực thông tin dùng MAC 16 Hình 1.6: Xác thực thông tin dùng hàm băm 17 Hình 1.7: Một ứng dụng điển hình hàm băm 19 Hình 1.8: Chữ ký trực tiếp .23 Hình 1.9: Xác thực thông tin dùng mật mã RSA dùng chữ ký số DSS 26 Hình 1.10: Tạo kiểm chứng chữ ký với DSS 27 Hình 1.11: Quản lý khoá công khai dùng chứng thực khóa (Certificate .30 Hình 1.12: Dùng mật mã bất đối xứng để trao đổi khoá .31 Hình 2.1: “Mã khóa riêng”, “mã khóa công khai”, “hệ thống bảo mật nhận dạng .37 Hình 2.2:Phương thức “mã khóa công khai” “chữ ký nhận dạng 38 Hình 2.3 Mã hoá hệ thống IBE 44 Hình 2.4 Giải mã hệ thống IBE 45 Hình 3.1 Mô hình hệ thống nhận dạng IBE 61 Hình 3.2: Hệ thống mã hoá mô hình bảo mật 62 Hình 3.3 Sơ đồ phân tích hệ thống 67 v DANH SÁCH CÁC BẢNG Trang Bảng 1.1 So sánh thông số SHA-1 MD5 20 Bảng 2.1 Bốn thuật toán tạo nên lược đồ IBE 46 Bảng 2.2 So sánh hệ thống IBE hệ thống khoá công khai truyền thống 54 LỜI MỞ ĐẦU Mã hóa dựa định danh (Indetity based encryption -IBE) xem công nghệ mật mã có nhiều thuận tiện thực thi ứng dụng so với thuật toán khóa công khai khác Đối với hệ mật mã khóa công khai truyền thống, việc cài đặt khó khăn tốn kém, ứng dụng thành công công nghệ khóa công khai việc sử dụng rộng rãi SSL, yêu cầu tương tác tối thiểu với người sử dụng dùng để xác thực máy chủ mã hóa truyền thông với máy chủ Các ứng dụng mà yêu cầu người sử dụng quản lý sử dụng khóa công khai không thành công IBE công nghệ mã hoá khoá công khai, cho phép người sử dụng tính khoá công khai từ chuỗi Chuỗi biểu diễn định danh dạng sử dụng không định danh để tính khoá công khai, mà chứa thông tin thời hạn hợp lệ khoá để tránh cho người sử dụng dùng khoá IBE để đảm bảo người sử dụng nhận khoá khác từ hệ thống IBE khác Trong chuỗi có chứa thông tin cài đặt IBE cụ thể, chẳng hạn URL mà định danh máy chủ sử dụng cài đặt hệ thống IBE khác Khả tính khoá mong muốn làm cho hệ thống IBE có tính chất khác với tính chất hệ thống khoá công khai truyền thống, tính chất tạo ưu thực hành đáng kể nhiều tình Bởi vậy, có số tình giải toán với công nghệ khoá công khai truyền thống, lại giải với IBE sử dụng IBE đơn giản nhiều cài đặt tốn nguồn lực để hỗ trợ IBE không đề xuất khả mà công nghệ khóa công khai truyền thống cung cấp cho phép tạo giải pháp để giải vấn đề khó khăn tốn triển khai công nghệ trước Đây lý để chọn đề tài có tên: Nghiên cứu mã hóa dựa định danh - IBE ứng dụng vào toán kiểm soát quyền truy cập hệ thống truyền hình trả tiền Nội dung nghiên cứu: - Nghiên cứu hệ mật mã khóa công khai truyền thống - Nghiên cứu hệ mã hóa dựa định danh ưu điểm hệ mã hóa so với hệ mã hóa công khai truyền thống - Ứng dụng mã hóa định danh bảo vệ thông tin Nội dung luận văn gồm chương: Chương 1: Tổng quan hệ mật mã khóa công khai Chương 2: Hệ mật mã dưa định danh Chương 3: Ứng dụng mã hóa dựa dịnh danh vào toán kiểm soát quyền truy cập hệ thống truyền hình trả tiền Chương TỔNG QUAN VỀ HỆ MẬT MÃ KHÓA CÔNG KHAI 1.1 Tổng quan mật mã 1.1.1 Giới thiệu Mật mã (Encryption) kỹ thuật sở quan trọng bảo mật thông tin Nguyên tắc mật mã biến đổi thông tin gốc thành dạng thông tin bí mật mà có thực thể tham gia xử lý thông tin cách hợp lệ hiểu Một thực thể hợp lệ người, máy tính hay phần mềm phép nhận thông tin Để giải mã thông tin mật, thực thể cần phải biết cách giải mã (tức biết thuật toán giải mã) thông tin cộng thêm (khóa bí mật) Quá trình chuyển thông tin gốc thành thông tin mật theo thuật toán gọi trình mã hoá (encryption) Quá trình biến đổi thông tin mật dạng thông tin gốc ban đầu gọi trình giải mã (decryption) Đây hai trình tách rời kỹ thuật mật mã mật mã (giấu thông tin) có ý nghĩa ta giải mã (phục hồi lại) thông tin Do vậy, dùng thuật ngữ mật mã có nghĩa bao hàm mã hóa giải mã Kỹ thuật mã hoá chia thành hai loại: mã hoá dùng khoá đối xứng (symmetric key encryption) mã hoá dùng khoá bất đối xứng (asymmetric key encryption) trình bày phần 1.1.2 Các thành phần hệ thống mã hoá Hình 1.1 mô tả nguyên tắc chung hệ thống mật mã quy ước Các thành phần hệ thống mật mã điển hình bao gồm: - Plaintext: thông tin gốc cần truyền hệ thống thông tinEncryption algorithm: thuật toán mã hóa, cách thức tạo thông tin mật từ thông tin gốc 82 BigInteger four = BigInteger.valueOf(4); BigInteger signOpenExp = BigInteger.valueOf(e); while (true) { P = BigInteger.probablePrime(security, new Random()); Q = BigInteger.probablePrime(security, new Random()); if (P.compareTo(Q) != && P.mod(four).compareTo(tree) == && Q.mod( four).compareTo(tree) == && signOpenExp.gcd(ResidueCalculation euler(P, Q)).compareTo(BigInteger.ONE) == 0) { break; } } MPK = P.multiply(Q); this.getSecretExponent(); } static public BigInteger genPkID(String id, BigInteger P, BigInteger Q, BigInteger MPK) throws NoSuchAlgorithmException { BigInteger a; int j = 0; int k = 0; MessageDigest md = MessageDigest.getInstance("SHA"); md.update(id.getBytes()); byte[] hash = md.digest(); a = new BigInteger(hash); a = a.abs(); a = a.mod(MPK); while (true) { j = ResidueCalculation.Jacobi(a, P); k = ResidueCalculation.Jacobi(a, Q); if (j == -1 && k == -1) { return MPK.subtract(a); } else if (j == && k == 1) { return a; } else { 83 a = a.add(BigInteger.ONE); } } } public BigInteger keyExtract(String id) throws NoSuchAlgorithmException { BigInteger SKE; BigInteger a = genPkID(id, P, Q, MPK); BigInteger exp = MPK.add(BigInteger.valueOf(5)).subtract(P.add(Q)) divide(BigInteger.valueOf(8)); SKE = a.modPow(exp, MPK); return SKE; } private void getSecretExponent() { BigInteger phi = ResidueCalculation.euler(P, Q); this.d = BigInteger.valueOf(e).modInverse(phi); } public BigInteger signKeyExtract(String id) throws NoSuchAlgorithmException { BigInteger SKS; MessageDigest md = MessageDigest.getInstance("SHA"); md.update(id.getBytes()); byte[] hash = md.digest(); BigInteger _id = new BigInteger(hash); SKS = _id.modPow(d, MPK); return SKS; } }File Util.java package org.suai.idbased.util; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.math.BigInteger; import org.suai.idbased.crypto.Cryptocontainer; public class Util { private final static int aesKeyLen = 128; static public byte[] KeyToBinary(byte[] raw) 84 { StringBuffer sb = new StringBuffer(); byte[] binaryKey; for (int i = 0; i < raw.length; i++) { String binary = null; binary = Integer.toBinaryString(raw[i] & 0xff); if (binary.length() < 8) { for (int k = 0; k < - binary.length(); k++) { sb.append("0"); } } sb.append(binary); } binaryKey = new byte[sb.length()]; for (int i = 0; i < sb.length(); i++) { binaryKey[i] = sb.charAt(i) == '0' ? (byte) : (byte) 1; } return binaryKey; } static public void GetEncryptedKey(DataInputStream din, boolean keytype, Cryptocontainer cc, BigInteger[] encryptedAESKey) throws IOException { int sizeofEncrAESKeyBit; din.skipBytes(8); if (keytype == false) { for (int i = 0; i < aesKeyLen; i++) { sizeofEncrAESKeyBit = din.readInt(); byte[] buff = new byte[sizeofEncrAESKeyBit]; din.read(buff); encryptedAESKey[i] = new BigInteger(buff); } din.skipBytes(cc.secondKeySize); } else 85 { din.skipBytes(cc.firstKeySize); for (int i = 0; i < aesKeyLen; i++) { sizeofEncrAESKeyBit = din.readInt(); byte[] buff = new byte[sizeofEncrAESKeyBit]; din.read(buff); encryptedAESKey[i] = new BigInteger(buff); } } } static public byte[] BinaryToByteKey(int[] binaryAESKey) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < binaryAESKey.length; i++) { sb.append(binaryAESKey[i]); } int from = 0, to = 8; String byte_of_key = new String(); byte[] raw = new byte[aesKeyLen/8]; String aes_key = sb.toString(); for (int i = 0; i < aesKeyLen/8; i++) { byte_of_key = aes_key.substring(from, to); raw[i] = Integer.valueOf(byte_of_key, 2).byteValue(); from = to; to = to + 8; } return raw; } static public void usage() { System.out.println ("\n"); System.out.println(" Clifford Cocks Identity Based Cryptosystem for mail server (autonome version) "); System.out.println(""); System.out.println("To run the program, type the following:"); System.out.println("java -jar ibc.jar command [parameters]"); System.out.println("List of available commands:"); System.out.println("setup"); System.out.println("keyextract"); System.out.println("encrypt"); System.out.println("decrypt"); System.out.println( 86 "Print help to see the details information of the program usage"); } static public void help() { System.out.println("\n"); System.out.println( "Please note: parameter order is irrelevant"); System.out.println(); System.out.println(" "); System.out.println("About setup:"); System.out.println( "Setup performs the initialization of Public Key Generator for domain and works with keystorage - " + "generate the necessary parameters for the cryptosystem, namely:"); System.out.println( "-MasterPublicKey generation of a given length (parameter security)"); System.out.println( "-MasterSecretKey generation of a given length (parameter security*2)"); System.out.println("These settings are stored in keystorage (encrypted by AES on password, specified by the user)" + "(parameters -keystorage and -mpk)"); System.out.println ("Otherwise, they are saved in the default directory"); System.out.println(); System.out.println("Usage:"); System.out.println( "setup -security 'positive integer' -mpk 'file_path' -keystorage 'path_to_keystorage' -domain 'domain-name (example@example.org)' -password 'root-pass-to-keystorage'"); System.out.println(" "); System.out.println(" "); System.out.println("About keyextract:"); System.out.println( "KeyExtract generates a secret key for encryption and signature for a user specified text identifier"); System.out.println ("In this case, you must specify the path to the master public key system, generated by running setup (if you are running with the -mpk parameter)"); System.out.println(); System.out.println("Usage"); System.out.println( "keyextract -keystorage 'path_to_keystorage' -password 'root-password-to-keystorage' -sk 'output_path_to_the_encryption_secret_key' -sks 'output_path_to_the_signing_secret_key' -domain 'domain-name' -id 'e-mail adress'"); System.out.println(" "); System.out.println(" "); System.out.println("About encrypt:"); System.out.println( "encrypt makes encryption and signature (cryptocontainer) of a user-specified file"); System.out.println("Usage:"); 87 System.out.println( "encrypt -to 'recipient-e-mail' -sks 'sender signing secret key' -mpk 'path_to_mpk'" + "-in 'path_to_the_file_for_encryption' -out 'output_path_to_the_encrypted_file'"); System.out.println(" "); System.out.println(" "); System.out.println("About decrypt"); System.out.println( "decrypt makes decryption and signature verification previously encrypted files"); System.out.println("Usage:"); System.out.println( "decrypt -sk 'path-to-recipient-encryption-secret-key'" + "-in 'path_to_the_encrypted_file' -out 'output_path_to_the_decrypted_file' -to 'your-e-mail-adres' -from 'sender email adress' -mpk 'path-to-mpk'"); System.out.println(" "); } static public void invalidParameters() { System.out.println( "Entered incorrect settings or missing required parameters, type help for calling tips"); } static public byte[] writeKeyData(BigInteger data) { return data.toByteArray(); } static public BigInteger readKeyData(FileInputStream in) throws IOException { byte[] byteKey = new byte[in.available()]; in.read(byteKey); return new BigInteger(byteKey); } } 3.2.4 Chương trình viết ngôn ngữ Java máy client File client.java package org.suai.idbased.crypto; import org.suai.idbased.util.Util; import org.suai.idbased.util.ResidueCalculation; import java.io.ByteArrayInputStream; 88 import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.math.BigInteger; import java.security.InvalidKeyException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Random; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.KeyGenerator; import javax.crypto.NoSuchPaddingException; import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; public class Client { private final int aesKeyLen = 128; private final int intLen = java.lang.Integer.SIZE/8; public BigInteger genPkID(String id, BigInteger MPK) throws NoSuchAlgorithmException { BigInteger a; int j = 0; MessageDigest md = MessageDigest.getInstance("SHA"); md.update(id.getBytes()); byte[] hash = md.digest(); a = new BigInteger(hash); a = a.abs(); a = a.mod(MPK); while (true) { j = ResidueCalculation.Jacobi(a, MPK); if (j == 1) { return a; } else { a = a.add(BigInteger.ONE); } } 89 } public void encryptKey(byte[] binaryKey, BigInteger[] ciphertext, BigInteger[] invCiphertext, BigInteger MPK, BigInteger PkID) { byte m = 0; int j = 0; BigInteger invT; BigInteger t; BigInteger b; Random rand = new Random(); int length = MPK.bitLength() / 4; int keyLength = binaryKey.length; for (int i = 0; i < keyLength ; i++) { m = binaryKey[i]; while (true) { t = new BigInteger(length, rand); j = ResidueCalculation.Jacobi(t, MPK); if ((m == && j == -1) || (m == && j == 1)) { invT = t.modInverse(MPK); b = PkID.multiply(invT); ciphertext[i] = t.add(b).mod(MPK); invCiphertext[i] = t.subtract(b).mod(MPK); break; } } } } private void writeEncryptedData(DataOutputStream dos, BigInteger[] ciphertext, BigInteger[] invCiphertext, byte[] encrypted_data) throws IOException { int keySizeFirst = 0; int keySizeScnd = 0; for (int i = 0; i < ciphertext.length; i++) { keySizeFirst = keySizeFirst + ciphertext[i].toByteArray().length; } for (int i = 0; i < invCiphertext.length; i++) { keySizeScnd = keySizeScnd + invCiphertext[i].toByteArray().length; 90 } dos.writeInt(keySizeFirst + this.aesKeyLen * this.intLen); dos.writeInt(keySizeScnd + this.aesKeyLen * this.intLen); for (int i = 0; i < ciphertext.length; i++) { dos.writeInt(ciphertext[i].toByteArray().length); dos.write(ciphertext[i].toByteArray()); } for (int i = 0; i < invCiphertext.length; i++) { dos.writeInt(invCiphertext[i].toByteArray().length); dos.write(invCiphertext[i].toByteArray()); } int encrypted_data_size = encrypted_data.length; dos.writeInt(encrypted_data_size); dos.write(encrypted_data); } private void writeSignature(FileInputStream fis, DataOutputStream dos, Sign signature, BigInteger MPK, BigInteger sk, long pk) throws IOException, NoSuchAlgorithmException { byte[] dataToHash = new byte[fis.available()]; fis.read(dataToHash); BigInteger[] sign = signature.getSign(dataToHash, sk, pk, MPK); dos.writeInt(sign[0].toByteArray().length); dos.writeInt(sign[1].toByteArray().length); dos.write(sign[0].toByteArray()); dos.write(sign[1].toByteArray()); } private void writeSignature(ByteArrayInputStream bis, DataOutputStream dos, Sign signature, BigInteger MPK, BigInteger sk, long pk) throws IOException, NoSuchAlgorithmException { byte[] dataToHash = new byte[bis.available()]; bis.read(dataToHash); BigInteger[] sign = signature.getSign(dataToHash, sk, pk, MPK); dos.writeInt(sign[0].toByteArray().length); dos.writeInt(sign[1].toByteArray().length); dos.write(sign[0].toByteArray()); dos.write(sign[1].toByteArray()); } 91 private boolean verifySignature(DataInputStream ds, Sign signature, String id, byte[] data, long pkey, BigInteger MPK) throws NoSuchAlgorithmException, IOException { byte[] tByte = new byte[ds.readInt()]; byte[] sByte = new byte[ds.readInt()]; ds.read(tByte); ds.read(sByte); BigInteger[] sign = new BigInteger[2]; sign[0] = new BigInteger(tByte); sign[1] = new BigInteger(sByte); return signature.verifySign(data, id, sign, pkey, MPK); } public int[] decryptKey(BigInteger[] encryptedAESKey, BigInteger SkID, BigInteger MPK, int keylength) { int[] binaryAESKey = new int[keylength]; int Jacobi; BigInteger root = SkID.add(SkID).mod(MPK); for (int i = 0; i < keylength; i++) { BigInteger currBit = encryptedAESKey[i].add(root); Jacobi = ResidueCalculation.Jacobi(currBit, MPK); if (Jacobi == 1) { binaryAESKey[i] = 1; } else { binaryAESKey[i] = 0; } } return binaryAESKey; } public byte[] encryptData(String inname, String outname, BigInteger PkID, BigInteger MPK, BigInteger sk, long pk) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IOException, IllegalBlockSizeException, BadPaddingException { FileOutputStream fout = new FileOutputStream(outname); 92 FileInputStream fin = new FileInputStream(inname); DataOutputStream dos = new DataOutputStream(fout); Sign signature = new Sign(); KeyGenerator kgen = KeyGenerator.getInstance("AES"); kgen.init(this.aesKeyLen); SecretKey skey = kgen.generateKey(); byte [] raw = skey.getEncoded(); SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, skeySpec); byte[] binaryKey = Util.KeyToBinary(raw); BigInteger [] ciphertext = new BigInteger[binaryKey.length]; BigInteger [] invCiphertext = new BigInteger[binaryKey.length]; encryptKey(binaryKey, ciphertext, invCiphertext, MPK, PkID); byte[] dataToEncrypt = new byte[fin.available()]; fin.read(dataToEncrypt); byte[] encryptedData = cipher.doFinal(dataToEncrypt); writeEncryptedData(dos, ciphertext, invCiphertext, encryptedData); FileInputStream fis = new FileInputStream(outname); writeSignature(fis, dos, signature, MPK, sk, pk); dos.close(); fout.close(); fis.close(); return dataToEncrypt; } public byte[] encryptData(ByteArrayInputStream is, BigInteger PkID, BigInteger MPK, BigInteger sk, long pk) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IOException, IllegalBlockSizeException, BadPaddingException { ByteArrayOutputStream out = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(out); Sign signature = new Sign(); KeyGenerator kgen = KeyGenerator.getInstance("AES"); kgen.init(this.aesKeyLen); SecretKey skey = kgen.generateKey(); byte[] raw = skey.getEncoded(); SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, skeySpec); byte[] binaryKey = Util.KeyToBinary(raw); BigInteger[] ciphertext = new BigInteger[binaryKey.length]; BigInteger[] invCiphertext = new BigInteger[binaryKey.length]; encryptKey(binaryKey, ciphertext, invCiphertext, MPK, PkID); byte[] dataToEncrypt = new byte[is.available()]; is.read(dataToEncrypt); byte[] encryptedData = cipher.doFinal(dataToEncrypt); writeEncryptedData(dos, ciphertext, invCiphertext, encryptedData); 93 ByteArrayInputStream bis = new ByteArrayInputStream (out.toByteArray()); writeSignature(bis, dos, signature, MPK, sk, pk); byte [] result = out.toByteArray(); dos.close(); out.close(); is.close(); return result; } public byte[] decryptData(String inname, String outname, String id, String idfrom, BigInteger SkID, BigInteger MPK, long pkey) throws FileNotFoundException, IOException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException { boolean negative = false; BigInteger[] encryptedAESKey = new BigInteger[this.aesKeyLen]; Cryptocontainer cc = new Cryptocontainer(); BigInteger pk = genPkID(id, MPK); BigInteger quadr = SkID.modPow(BigInteger.valueOf(2), MPK); Sign signature = new Sign(); if (quadr.compareTo(pk) == 0) { negative = false; } else { negative = true; } FileInputStream fin = new FileInputStream(inname); DataInputStream ds = new DataInputStream(fin); cc = cc.getCryptocontainerParameters(ds); if (cc == null) { return null; } ds.close(); fin.close(); fin = new FileInputStream(inname); ds = new DataInputStream(fin); byte[] data = new byte[cc.dataSize - cc.signatureSize]; ds.read(data); boolean check = verifySignature(ds, signature, idfrom, data, pkey, MPK); if (check == false) { return null; } fin.close(); ds.close(); 94 fin = new FileInputStream(inname); DataInputStream din = new DataInputStream(fin); Util.GetEncryptedKey(din, negative, cc, encryptedAESKey); int[] binaryAESKey = decryptKey(encryptedAESKey, SkID, MPK, this.aesKeyLen); byte[] raw = Util.BinaryToByteKey(binaryAESKey); din.close(); SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, skeySpec); byte[] encryptedData = new byte[cc.encryptedDataSize]; System.arraycopy(data, cc.firstKeySize + cc.secondKeySize + 12, encryptedData, 0, cc.encryptedDataSize); byte[] decryptedData = cipher.doFinal(encryptedData); FileOutputStream fos = new FileOutputStream(outname); fos.write(decryptedData); fos.close(); return decryptedData; } public byte[] decryptData(ByteArrayInputStream is, String id, String idfrom, BigInteger SkID, BigInteger MPK, long pkey) throws FileNotFoundException, IOException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException { boolean negative = false; BigInteger[] encryptedAESKey = new BigInteger[128]; Cryptocontainer cc = new Cryptocontainer(); BigInteger pk = genPkID(id, MPK); BigInteger quadr = SkID.modPow(BigInteger.valueOf(2), MPK); Sign signature = new Sign(); if (quadr.compareTo(pk) == 0) { negative = false; } else { negative = true; } DataInputStream ds = new DataInputStream(is); cc = cc.getCryptocontainerParameters(ds); if (cc == null) { return "[IBC JAMES MAILET]: Failed to decrypt: letter was changed (Cryptocontainer is damaged)".getBytes(); } ds.close(); is.reset(); ds = null; 95 ds = new DataInputStream(is); byte[] data = new byte[cc.dataSize - cc.signatureSize]; ds.read(data); boolean check = verifySignature(ds, signature, idfrom, data, pkey, MPK); if (check == false) { return "[IBC JAMES MAILET]: Failed to decrypt: maybe a letter was changed (Error during signature verification)".getBytes(); } is.reset(); ds.close(); DataInputStream din = new DataInputStream(is); Util.GetEncryptedKey(din, negative, cc, encryptedAESKey); int[] binaryAESKey = decryptKey(encryptedAESKey, SkID, MPK, this.aesKeyLen); byte[] raw = Util.BinaryToByteKey(binaryAESKey); din.close(); SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, skeySpec); byte[] encryptedData = new byte[cc.encryptedDataSize]; System.arraycopy(data, cc.firstKeySize + cc.secondKeySize + 12, encryptedData, 0, cc.encryptedDataSize); return cipher.doFinal(encryptedData); } } 96 ... công nghệ trước Đây lý để chọn đề tài có tên: Nghiên cứu mã hóa dựa định danh - IBE ứng dụng vào toán kiểm soát quyền truy cập hệ thống truy n hình trả tiền Nội dung nghiên cứu: - Nghiên cứu hệ mật... - Nghiên cứu hệ mật mã khóa công khai truy n thống - Nghiên cứu hệ mã hóa dựa định danh ưu điểm hệ mã hóa so với hệ mã hóa công khai truy n thống - Ứng dụng mã hóa định danh bảo vệ thông tin... quan hệ mật mã khóa công khai Chương 2: Hệ mật mã dưa định danh Chương 3: Ứng dụng mã hóa dựa dịnh danh vào toán kiểm soát quyền truy cập hệ thống truy n hình trả tiền Chương TỔNG QUAN VỀ HỆ

Ngày đăng: 16/04/2017, 17:31

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w