Skip to content

Instantly share code, notes, and snippets.

View luiswolff's full-sized avatar

Luis-Manuel Wolff Heredia luiswolff

View GitHub Profile
@echo off
rem install angular cli if not already done
npm install -g @angular/cli
rem create workspace with routing module and not interaction
ng new webapp --routing --defaults
rem enter workspace
cd webapp
// For more information see: https://stackoverflow.com/questions/2897619/using-html5-javascript-to-generate-and-save-a-file
var pom = document.createElement('a');
pom.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent('hello world!'));
pom.setAttribute('download', 'test.txt');
if (document.createEvent) {
var event = document.createEvent('MouseEvents');
event.initEvent('click', true, true);
pom.dispatchEvent(event);
}
@luiswolff
luiswolff / WSSecurityVerifier.java
Created June 5, 2019 19:54
This gist shows how to verify a signed Soap-Message using Apache WSS4J
package de.wolff.wsst;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Properties;
import java.util.regex.Pattern;
@luiswolff
luiswolff / WSSecuritySigner.java
Created June 5, 2019 19:52
This gist shows how to sign a Soap-Message using Apache WSS4J.
package de.wolff.wsst;
import java.io.File;
import java.util.Properties;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPMessage;
import org.apache.wss4j.common.crypto.Crypto;
@luiswolff
luiswolff / java-keytool-sign-certificate.cmd
Last active June 5, 2019 19:57
This gist show how to create a self signed certificate (bob) and use it to sign a other (alice). So a application only requires to know the public key of bob in order to trust alice, too. The Java Keytool is used.
rem # create a new self signed certificate insite the keystore bob.jks. This will act as issuer for the other certificate
rem # It is importent to add the extention BasicConstraints Certificate Authority (bc:c)
rem # Otherwise tools like the JVM will not accept other certificates issued by this
keytool -genkey -alias bob -keyalg RSA -keypass changeit -storepass changeit -keystore bob.jks -dname CN=bob -ext bc:c
rem # create a other self siged certificate for with we will create a Certificate Sign Request (CSR)
keytool -genkey -alias alice -keyalg RSA -keypass changeit -storepass changeit -keystore alice.jks -dname CN=alice
package de.wolff.dsi;
public interface DynamicService {
String invoke();
}
@luiswolff
luiswolff / MessageSignVerifier.java
Created December 21, 2018 15:14
Example on how to verify a data file using a provided signature and public key.
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.KeyFactory;
import java.security.PublicKey;
import java.security.Signature;
import java.security.spec.X509EncodedKeySpec;
public class MessageSignVerifier {
@luiswolff
luiswolff / MessageSignGenerator.java
Created December 21, 2018 15:12
Example on how to sign file content using a randomly generated private Key. The Code takes a file as input and generates a signature and a public key, that can be used to verify, that the signature was create by the generated private key.
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.SecureRandom;
import java.security.Signature;
@luiswolff
luiswolff / MessageDESEncrypter.java
Created December 21, 2018 12:47
Example how to encrypt a message with a provided secret using the Data Encryption Standard algorithm. The message is writen to a given file. The provided secret is required to have exactly 8 characters.
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Cipher;
import javax.crypto.CipherOutputStream;
import javax.crypto.NoSuchPaddingException;
@luiswolff
luiswolff / MessageDESDecrypter.java
Last active December 21, 2018 12:47
Example how to decrypt a protected message with a provided secret using the Data Encryption Standard algorithm. The messaged is readed from a provided file and the printed to the console. The provided secret is required to have exactly 8 characters.
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;