public static String KeyDecrypt(PRE_KEY key2, PRE_Cipher CC) { IntPtr pKey2 = KeyStr2KeyPtr(key2); IntPtr C = CipherStr2CipherPtr(CC); return(KeyDecrypt(pKey2, C)); }
public static PRE_Cipher KeyEncrypt(PRE_KEY key1, PRE_PK key2_pk, String m) { IntPtr pKey1 = ProxyReEncryption.KeyStr2KeyPtr(key1); IntPtr pPk2 = ProxyReEncryption.PKStr2PKPtr(key2_pk); IntPtr C = KeyEncrypt(pKey1, pPk2, m); PRE_Cipher CC = CipherPtr2CipherStr(C); return(CC); }
public static PRE_KEY GenKey(String pk1, String pk2, String sk1, String sk2) { PRE_KEY key = new PRE_KEY(); key.PK = new PRE_PK(); key.SK = new PRE_SK(); key.PK.PK1 = pk1; key.PK.PK2 = pk2; key.SK.X1 = sk1; key.SK.X2 = sk2; return(key); }
static void PRETEST() { String m = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"; PRE_KEY key1 = ProxyReEncryption.GenRandomKey(); PRE_KEY key2 = ProxyReEncryption.GenRandomKey(); PRE_Cipher keyC = ProxyReEncryption.KeyEncrypt(key1, key2.PK, m); String mm = ProxyReEncryption.KeyDecrypt(key2, keyC); Console.WriteLine(mm + mm.Length); Console.Read(); }
private void ShareWorker_DoWork(object sender, DoWorkEventArgs e) { while (this.ShareTaskWaitingList.Count != 0) { for (int i = this.ShareTaskWaitingList.Count - 1; i >= 0; i--) { ShareTaskUnit worker = this.ShareTaskWaitingList[i]; PublicKey pubkey = worker.PK; //Key1 PRE_KEY key = ProxyReEncryption.GenKey( PreKeyring.UserKey.PK1, PreKeyring.UserKey.PK2, PreKeyring.UserKey.SK1, PreKeyring.UserKey.SK2); //Key_pk2 PRE_PK key2_pk = ProxyReEncryption.GenPK(pubkey.PK1, pubkey.PK2); //ReKey PRE_Cipher reKey = ProxyReEncryption.KeyEncrypt(key, key2_pk, worker.Key); String cpyRef = this.DropboxController.GetCopyRef( this.DropboxController.SecuruStikFolder2RemoteDropboxPath(worker.FilePath)); if (String.IsNullOrEmpty(cpyRef)) { continue;//获取copyref失败处理 } else { worker.CpyRef = cpyRef; } SecuruStik.Protocal.SharingInfo si = new SecuruStik.Protocal.SharingInfo( this.Email, pubkey.ID, Path.GetFileName(worker.FilePath), worker.CpyRef, reKey.E, reKey.F, reKey.U, reKey.W); Request r = new Request(MessageType.Request_SetSharingInfo, this.DropboxController.Email, si); this.ProxyServerController.Send(r); this.ShareTaskWaitingList.Remove(worker); SecuruStikMessageQueue.SendMessage_Share_End(Path.GetFileName(worker.FilePath), worker.ID_TO); } } }
public void ReGenUserKey() { //Create a new user key PRE_KEY key = ProxyReEncryption.GenRandomKey(); this.PK = new Protocal.PublicKey( id: this.dropBoxController.Email, pk1: key.PK.PK1, pk2: key.PK.PK2); PreKeyring.UserKey = new SecuruStik.DB.UserKey { PK1 = key.PK.PK1, PK2 = key.PK.PK2, SK1 = key.SK.X1, SK2 = key.SK.X2, IsPublicized = false }; }
public Boolean DownloadSharingFile(Protocal.SharingInfo si) { String copyRef = si.Reference; String fileName = si.FileName; try { String dropboxPath = BaseExtension.FileStringHelper.GetNonConflictFileName(Path.Combine(DropBoxController.DropBox_DownloadFolder, fileName)); UserKey uk = PreKeyring.UserKey; PRE_KEY userKey = new PRE_KEY(); userKey.PK.PK1 = uk.PK1; userKey.PK.PK2 = uk.PK2; userKey.SK.X1 = uk.SK1; userKey.SK.X2 = uk.SK2; PRE_Cipher CKey = new PRE_Cipher(); CKey.E = si.CKey_E; CKey.F = si.CKey_F; CKey.U = si.CKey_U; CKey.W = si.CKey_W; String key = ProxyReEncryption.KeyDecrypt(userKey, CKey); FileMetaData fi = new FileMetaData(); fi.FileName = fileName; fi.FilePath = this.dropBoxController.DropboxSecuruStikFolder2SecuruStikFolder(dropboxPath); fi.Key = key; fi.PlainTextHash = ""; fi.CryptTextHash = ""; PreKeyring.FileInfo_Update(fi); String dropboxRemotePath = this.dropBoxController.SecuruStikFolder2RemoteDropboxPath(fi.FilePath); this.dropBoxController.CopyAsync(copyRef, dropboxRemotePath); } catch (System.Exception ex) { log.ErrorFormat("DownloadSharingFile {0}", si.FileName, ex); PreKeyring.SharingFile_Delete(si.Reference); return(false); } return(true); }
private static IntPtr KeyStr2KeyPtr(PRE_KEY key) { PRE_ptrPK ptrPK = new PRE_ptrPK { pk1 = Marshal.StringToHGlobalAnsi(key.PK.PK1), pk2 = Marshal.StringToHGlobalAnsi(key.PK.PK2) }; IntPtr pPk = Marshal.AllocHGlobal(Marshal.SizeOf(ptrPK)); Marshal.StructureToPtr(ptrPK, pPk, true); PRE_ptrSK ptrSK = new PRE_ptrSK { x1 = Marshal.StringToHGlobalAnsi(key.SK.X1), x2 = Marshal.StringToHGlobalAnsi(key.SK.X2) }; IntPtr pSk = Marshal.AllocHGlobal(Marshal.SizeOf(ptrSK)); Marshal.StructureToPtr(ptrSK, pSk, true); PRE_ptrKEY keyPtr = new PRE_ptrKEY { pk = pPk, sk = pSk }; IntPtr pKey = Marshal.AllocHGlobal(Marshal.SizeOf(keyPtr)); Marshal.StructureToPtr(keyPtr, pKey, true); return(pKey); }