Code Snippets für VS Lab Test

Similar documents
Search Engines Chapter 2 Architecture Felix Naumann

Auskunftsbegehren gemäß Art 15 DSGVO (Facebook Version englisch) - V1.0

Installing and Configuring Windows 10 MOC

Ulrich Stärk

Verteilte Systeme UE Important Code

Dwg viewer free download vista. Dwg viewer free download vista.zip

Using extensible metadata definitions to create a vendor independent SIEM system

WorldCat Local Release Notes 13 November 2011

Anleitung zur Schnellinstallation TEW-684UB 1.01

1. Übungsblatt. Vorlesung Embedded System Security SS 2017 Trusted Computing Konzepte. Beispiellösung

Slides by Kent Seamons and Tim van der Horst Last Updated: Oct 7, 2013

Windows Update error code list

Developing Microsoft Azure Solutions MOC 20532

WorldCat Local Release Notes 21 August 2011 Contents

Design and implementation of Virtual Security Appliances (VSA) for SME

Exchange 2016 Mailbox Move Request

Manual Android Galaxy S2 Update 4.0 Kies Anleitung

Flasher Utility. QUANCOM Informationssysteme GmbH

USB. USB Sticks in Design und Qualität

COURSE LISTING. Courses Listed. Training for Analytics with Business Warehouse (BW) in SAP BW powered by SAP HANA. Last updated on: 23 Nov 2018

Intro (with some history) Issues ow, ow, ow, ow, ow, ow, ow, ow, Disclosure/Timeline CHIASMUS cipher

SD2IEC evo². Revision E3b

PAR-KL-68. QUANCOM Informationssysteme GmbH

Datenblatt: True Flat Touch Screens

AMIGA WORKBENCH AMIGA WORKBENCH 1 3 AMIGA WORKBENCH 1 3 PDF WORKBENCH (AMIGAOS) - WIKIPEDIA AMIGAOS - WIKIPEDIA 1 / 5

TDM+VoIP Smart Media Gateway

Rib Design to Increase Stiffness of Housings

Manual Update V

INVENTOR MECHANICAL DESIGN & 3D CAD SOFTWARE AUTODESK AUTOCAD FOR MAC & WINDOWS CAD SOFTWARE AUTODESK

Modern and Lucid C++ for Professional Programmers. Week 15 Exam Preparation. Department I - C Plus Plus

AUTOMATISIERUNG DER INFRASTRUKTUR

Birol ÇAPA Doç. Dr. Sıddıka Berna Örs Yalçın Following code can coompute montgomery multiplication of 128 bit numbers:

Das Seminar kann zur Vorbereitung auf die Zertifizierung als Microsoft Certified Solutions Developer (MCSD): SharePoint Applications genutzt werden.

CDP 1440i/2440i Getting Started Guide

Extract from Project Report

CANOpen DS402 at KEBA

Zielgruppe Dieser Kurs eignet sich für Cloud- und Rechenzentrumsadministratoren.

TI-No. 4002TI05.doc PAGE NO. : 1/1. Settings after Installation of the Firmware Version 74

Contents. Configuring SSH 1

Continuous Delivery. für Java Anwendungen. Axel Fontaine Software Development Expert

Copyright 2004 by SMC Networks, Inc. 38 Tesla Irvine, California All rights reserved.

ProCANopen Questions & Answers Version Application Note AN-ION

THE CLOUD. Who Owns Your Data?

AC500. Application Note. Scalable PLC for Individual Automation. AC500-S safety PLC - Overview of changes in Automation Builder 2.1.x and 2.0.

4. Multicast Multicast Principles. Why is Multicast Important for. Multimedia? Definition of Multicast

Monitoring & Automation with OP5 & Stonebranch A presentation in German - English

10/25/ Recursion. Objectives. Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich.

Übungsfragen für den Test zum OMG Certified UML Professional (Intermediate) Download

EUCEG: Encryption process

Table of contents 2 / 12

IN THE PRODUCT LINE MODEL VERSIONING DEVELOPMENT. Supported by Enterprise Architect and LemonTree

DOWNLOAD PERFECT WILLST DU DIE PERFEKTE WELT

Emerging Technologies Workshops

Artisan Technology Group is your source for quality new and certified-used/pre-owned equipment

Planning for and Managing Devices in the Enterprise: Enterprise Mobility Suite (EMS) & On-Premises Tools MOC 20398

file:///h:/temp/htmlö/analyse+dfsio+write+test.html

Internet Protocol (IP) TCP versus UDP

huawei configuration 3E5E5C3156BED808DD5646BC382CA821 Huawei Configuration 1 / 6

AW-Information sheet Swissmedic egov Portal Standard functions

Praktische Aspekte der Informatik. Thomas Löwe Prof. Marcus Magnor

Aufgabe 2. Join-Methoden Differential Snapshots. Ulf Leser Wissensmanagement in der Bioinformatik

FLASH INSIGHT. The internet giants media mobilisation Do they play turtle and hare with us?

... Chair of Mobile Business & Multilateral Security. Lecture 14 Business Informatics 2 (PWIN) Q&A SS 2017

AusweisApp2 Manual Release

Neuigkeiten aus dem Oracle-Cloud-Portfolio - Fokus auf Infrastructure-as-a-Service

CSCE 715: Network Systems Security

Network Programming. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff

Softwareverteilung HotPotatoes

DOWNLOAD OR READ : QUICK CORBA 3 OBJECT MANAGEMENT GROUP BOOK 1 PDF EBOOK EPUB MOBI

Designing Database Solutions for Microsoft SQL Server 2012 MOC 20465

Java Networking (sockets)

Form Configuration. You will have to be logged in in OPAS as the same User that you wish to configure the form for.

IPC-610F. Industrial PC Chassis

Lotus Connections Architektur und Installation IBM Corporation

Übersicht Port-Liste. Workstation. Liste der in SeMSy III verwendeten Netzwerk-Ports

Security Protocols and Infrastructures. Winter Term 2010/2011

Unavoidable trees and forests in graphs

HOW THE INTERNET OF THINGS IS CHANGING THE WAY WE WORK

Download google chrome version 44 Google Chrome Google

Introduction to Computational Linguistics

Cipher Suite Configuration Mode Commands

Inside the World of Cryptographic Algorithm Validation Testing. Sharon Keller CAVP Program Manager NIST ICMC, May 2016

PIC Council Charter. Jürgen Wagner, Friedhelm Krebs. SAP AG Version 1.1 April 26 th, 2004

Bechtle Solutions Update VMware Horizon 7 What s New

IPC Industrial PC Chassis. User's Manual

NEUHEITEN NOVELTIES 2018

Data Security and Privacy. Topic 14: Authentication and Key Establishment

Structured Peer-to-Peer Services for Mobile Ad Hoc Networks

Übungsblatt 2. Aufgabe 1 (Klassifikationen von Betriebssystemen)

Cryptography - SSH. Network Security Workshop May 2017 Phnom Penh, Cambodia

MULTIBASELINE INTERFEROMETRIC SAR AT MILLIMETERWAVES TEST OF AN ALGORITHM ON REAL DATA AND A SYNTHETIC SCENE

Cryptography - SSH. Network Security Workshop. 3-5 October 2017 Port Moresby, Papua New Guinea

Washington State University CptS 455 Sample Final Exam (corrected 12/11/2011 to say open notes) A B C

DOWNLOAD OR READ : VISUAL C MFC PROGRAMMING BY EXAMPLE PDF EBOOK EPUB MOBI

Cryptography. If privacy is outlawed, only outlaws will have privacy. Zimmerman (author of PGP) 1/18

FPM-3120TH Series. Flat Panel Monitor with 12" Color TFT/LCD Display. User's Manual

Information System Security

SECURE DATA EXCHANGE. Version

FAQ Communication over IE

Kreative Bedienkonzepte mittels jqueryui

Transcription:

Code Snippets für VS Lab Test Beinhaltet TCP, UDP, RMI sowie diverse Security Dinger. Großteils wurde der Code von Lab1 Lab2 genommen, bzw. aus dem TUWEL Faq. Es kann natürlich sein, dass Fehler enthalten sind, also bitte mit kritischem Auge betrachten ;). Exceptions wurden hier für die Leserlichkeit komplett weggelassen, Eclipse wird einen jedoch darauf aufmerksam machen, vondem her sollte das kein großes Problem sein. Viel Spaß beim Lernen. TCP: Client Setup for short communication: UDP: Client Setup for short communication RMI: Client Setup Server Setup SECURITY: BASE64 en/decoding Secure Random Number AES encryption / decryption RSA encryption / decryption HMac

TCP: synchronous Server Client communication. Client Setup for short communication: Socketsocket=newSocket("localhost", 1337); BufferedReaderreader=newBufferedReader(new InputStreamReader(socket.getInputStream())); // thetrueisveryimportantfortheautoflush PrintWriterwriter=newPrintWriter(socket.getOutputStream(), true); // writetoserver writer.println("requesttoserver"); // printoutanswer System.out.println(reader.readLine()); // Don tclosewriterorreaderbecausetheythrowexceptions. this.socket.close(); // ServerSocketonlyneedsport, nohost ServerSocketserverSocket=newServerSocket(1337); SocketclientSocket=serverSocket.accept(); BufferedReaderreader=newBufferedReader(new InputStreamReader(clientSocket.getInputStream())); PrintWriterwriter=newPrintWriter(clientSocket.getOutputStream(), true); Stringrequest=reader.readLine(); /* * DOSOMETHINGWITHREQUEST:D */ // answertoclient writer.println("responsetoclient"); // Don tclosewriterorreaderbecausetheythrowexceptions. if(serversocket!=null&&!serversocket.isclosed()) serversocket.close(); if(clientsocket!=null&&!clientsocket.isclosed()) clientsocket.close();

UDP: a synchronous Server Client communication. Client Setup for short communication // CLIENTHASEMPTYCONSTRUCTOR DatagramSocketsocket=newDatagramSocket(); StringmessageForUDP="THISISAMESSAGE"; byte[] buffer=messageforudp.getbytes(); // createthepacket DatagramPacketpacket=newDatagramPacket(buffer, buffer.length, InetAddress.getByName(serverhost), udpport); // sendthepacketoff socket.send(packet); // Nowwegonnawaitforapacket, setupthebufferandpacketfirst: buffer=newbyte[1024]; packet=newdatagrampacket(buffer, buffer.length); // thereceiveblocksandwaitstillpacketarrives socket.receive(packet); // Printoutwhatwereceived System.out.println(newString(packet.getData())); socket.close(); // SERVERHASPORTINCONSTRUCTOR DatagramSocketsocket=newDatagramSocket(udpPort); // Nowwegonnawaitforapacket, setupthebufferandpacketfirst: byte[] buffer=newbyte[1024]; DatagramPacketpacket=newDatagramPacket(buffer, buffer.length); // thereceiveblocksandwaitstillpacketarrives socket.receive(packet); Stringrequest=newString(packet.getData())); Stringresponse=newString("response"); // ToreturntoClientwegetAddressandPortfromPacket InetAddressaddress=packet.getAddress(); intport=packet.getport(); buffer=response.getbytes(); packet=newdatagrampacket(buffer, buffer.length, address, port); socket.send(packet); socket.close();

RMI: registry thingy for putting addresses and looking them up. Client Setup // getremoteserverobjectfromregistry Registryregistry=LocateRegistry.getRegistry(host, port); IServerRemoteremote=(IServerRemote) registry.lookup(servername); // nowyoucanusethemethodsfromiserverremote(examplefrommuster test) remote.bye(); Server Setup // createregistryonport Registryregistry=LocateRegistry.createRegistry(port); // remoteobistheremoteobject, inourcaseaninstanceofiserverremote( > this) IServerRemoteremote=(IServerRemote) UnicastRemoteObject.exportObject(remoteOb, 0); // bindremoteobjecttoanameintheregistry registry.bind(bindingname, remote); // THAT SITATTHISPOINT, NOWFORCLOSING // remoteobissameasbefore( >this) andtrueisforforcingit UnicastRemoteObject.unexportObject(remoteOb, true); if(registry!=null){ // don tforgettounbindafterunexporting registry.unbind(bindingname); UnicastRemoteObject.unexportObject(registry, true); } //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // theiserverremotehasttousetheremoteinterfaceandallmethodsthatwillbe // calledoverrmihavetothrowtheremoteexception

SECURITY: BASE64 en/decoding // getarandomstringmessageinbyte byte[] message=newstring("thisisamessage").getbytes(); // encodethemessage byte[] base64encoded=base64.encode(message); // decodethemessage byte[] base64decoded=base64.decode(base64encoded); // togofrombytetostring StringmessageEncoded=newString(base64encoded); Secure Random Number SecureRandomsecureRandom=newSecureRandom(); finalbyte[] number=newbyte[32]; securerandom.nextbytes(number); AES encryption / decryption // CREATEIV >nothingbutarandom16bitbytearray SecureRandomiv=newSecureRandom(); finalbyte[] number=newbyte[16]; iv.nextbytes(number); // CREATEtheKEY, AESthereforeAESInstance KeyGeneratorgenerator=KeyGenerator.getInstance("AES"); // KEYSIZEisinbits generator.init(keysize); SecretKeykey=generator.generateKey(); // ENCRYPTYOURINPUT Ciphercipher=Cipher.getInstance(AESCONFIG); cipher.init(cipher.encrypt_mode, key, newivparameterspec(iv)); byte[] encrypted=cipher.dofinal(input); // ENCRYPTIONANDDECRYPTIONISTHESAMEEXCEPTFORTHECIPHER_MODE!!!!!!! // DECRYPTYOURINPUT Ciphercipher=Cipher.getInstance(AESCONFIG); cipher.init(cipher.decrypt_mode, key, newivparameterspec(iv)); byte[] decrypted=cipher.dofinal(input);

RSA encryption / decryption // RSAWEUSETHEPUBLICANDPRIVATEKEYS, shouldbegivenasfile, alsowedon t // needanivobject // ENCRYPTYOURINPUTWITHPUBLICKEY Ciphercipher=Cipher.getInstance(RSACONFIG); cipher.init(cipher.encrypt_mode, publickey);//!!!! PUBLICKEY byte[] encrypted=cipher.dofinal(input); // ENCRYPTIONANDDECRYPTIONISTHESAMEEXCEPTFORTHECIPHER_MODEANDKEY!!!!!!!! // DECRYPTYOURINPUTWITHPRIVATEKEY Ciphercipher=Cipher.getInstance(RSACONFIG); cipher.init(cipher.decrypt_mode, privatekey);//!!!! PRIVATEKEY byte[] decrypted=cipher.dofinal(input); HMac // HMACCHECK // keyisthesecretkey, messageisthemessagewereceived // ThisisbasicallyalsohowyoucreateahMac MachMac=Mac.getInstance("HmacSHA256"); hmac.init(key); hmac.update(message.getbytes(standardcharsets.utf_8)); byte[] calculatedhash=hmac.dofinal(); // receivedhashisthehashthatwereceivedwiththemessage returnmessagedigest.isequal(calculatedhash, receivedhash);