Tag Archives: algorithm

Digital Signature explanation

The security is very important concept today for all type of systems. So, we have to know how to protect your data from theft, hijacking, etc.
Encryption is reversible conversion of data to hide payload from other reading.

The are two types of encryption algorithms:
1. Symmetric Encryption (Private-key (or secret-key) cryptography).
priv-key
Uses the same key for encryption and decryption of message.

2. Asymmetric Encryption (Public-key cryptography).
pub-key
Uses public key for encryption and private key for decryption of message.

 

The payload messages usually use digital signature for protection. Explanation of how the digital signature works below in a few steps:

1. Angela wants to send a message to Hugo.
1

 

2. Angela request a certificate from Certification Center.
2

 

3. Certification Center sends a certificate with public-private key pair.
3

 

4. Angela calculates hash of message. Encrypts obtained hash with private key – this is a Digital Signature! And attach DS to message.
4

 

5. Angela sends DS, Message and certificate to Hugo.
5

 

6. Hugo decrypts digital signature with public key. Take a hash from Message. Then, he checks decrypted value and hash for equality. If values are equal – message is valid and it can be read, otherwise – message is invalid!
6

 

See also,
https://en.wikipedia.org/wiki/Symmetric-key_algorithm
https://en.wikipedia.org/wiki/Public-key_cryptography
http://en.wikipedia.org/wiki/Digital_signature
https://en.wikipedia.org/wiki/Hash_function

http://en.kioskea.net/contents/130-private-key-or-secret-key-cryptography
http://en.kioskea.net/contents/131-public-key-systems

SOLID principle in OOP design

solid
Just to remember the issue.

SOLID is:

SRP -Single responsibility principle
A class should have only a single responsibility.

OCP – Open/closed principle
“Software entities … should be open for extension, but closed for modification”.

LSP – Liskov substitution principle
“Objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program”.

ISP – Interface segregation principle
“Many client-specific interfaces are better than one general-purpose interface.”

DIP – Dependency inversion principle
One should “Depend upon Abstractions. Do not depend upon concretions.”

Source link

Dynamically render content in columns


It is need to render some content in columns often if you know columns count.

writer.startElement("table", this);
writer.writeAttribute("border", "0", null);
writer.writeAttribute("style", "width: 100%;", null);
writer.startElement("tr", this);

int nColCount = 2;
int nRowCount = properties.size() / nColCount;
int nFirstRowCount = nRowCount + (properties.size() - (nRowCount * nColCount));

int nCnt = 0;
boolean isFirstColWrited = false;
for (Entry> entry : properties.entrySet()) {
	if (nCnt == 0) {
		writer.startElement("td", this);
		writer.writeAttribute("valign", "top", null);
	} else {
		if (!isFirstColWrited && nCnt % nFirstRowCount == 0) {
			writer.endElement("td");
			writer.startElement("td", this);
			writer.writeAttribute("valign", "top", null);
			isFirstColWrited = true;
		} else if (isFirstColWrited && nCnt % nRowCount == 0) {
			writer.endElement("td");
			writer.startElement("td", this);
			writer.writeAttribute("valign", "top", null);
		}
	}
	// Payload
	String groupName = entry.getKey();
	List groupProperties = entry.getValue();
	writeGroup(writer, groupName, groupProperties);

	nCnt++;
}

writer.endElement("tr");
writer.endElement("table");

properties.size() – some map with data
writer – javax.faces.context.ResponseWriter

Inversion of Control (IoC)


So many thoughts about subject. But imho,

IoC is a setting realization to class properties