Posts

Showing posts from November, 2021

HASHLIB: Using HASH functions MD5 and SHA256

Image
  The usage of hash functions in python is quite simple. Basically we can use the native library hashlib, which give us the possibly to create message digest based on several algorithms, such as MD5 or SHA256. Using this library we may create a hash of some content and then retrieve its binary output or transform that in hexadecimal strings to easy the data transfer in different medias. The library can be imported with the following instruction: import hashlib   If you want to encode strings, it is necessary to encode that with UTF-8, and it can be done using the encode method of a string object: myPassword= "python3.x" myPasswordEncoded=myPassword.encode( 'utf-8' )       The n, the hashlib module has a md5 function which receives as parameter the the we would like to generate the hash. And then return the hash object. hashObject=hashlib.md5(myPasswordEncoded)   The hashObject already contains the ...

Yield - Generator Functions

Image
The generator functions provide a simple way to program a iterator using native resources of the java script programming language. It provide a simple syntax for blocking and continue the flow of a function executing based on interactions with this function. It is quite useful to any function that has to process a certain dataset, but just a part by time, optimizing the processing and memory consumption. A generator function is a normal java script function that has a “*” at the side of the function name. It means this function when being its execution is allowed to stop in a blocking way, as soon as it found the yield keyword. In this moment the value that the right of yield is returned, and the function execution is blocked until this function is called gain through the .next() method. function* generator_function ( index ) {     while ( index < 2 ) {       yield index ;       index ++;     }   }   Th...

Executing your first React Native project

Image
  For develop with react native you need to have installed in your computer node.js and Android Studio. The node.js though npm will assist you to download the dependencies, specially the expo-cli package and Android Studio will contains the android SDK and the android device manager to assist in the developing x testing process. The first thing you have to do is to download the expo-cli executing the following instruction: npm install -g expo-cli. The expo-cli will provide you means to create and then to execute react-native apps, besides several other features such as the live reloading of you changes. Once expo-cli is available, you can then create a react native project using the following instruction: expo init. It will ask you to give a name to the project and then a template. For template you may choose blank, as suggestion. You have to wait until the project creation is completed. Once it the project is created you may run the executing the instruction: expo start. Jus...

Validating digital signature based on .p7s files

Image
  The digital signature is a reality for many software applications. One typical format to store the digital signature is using the .p7s file ( https://www.reviversoft.com/en/file-extensions/p7s ) which contains information about how has signed a certain file, what algorithm was utilized for signing, and also what is the hash of produced file.   In this post we are going to demonstrate an example of how to validate a p7s file signature when we have the original file and the .p7s file. First, we need a library for this purpose. In this example we are going to use the demoiselle ( https://github.com/demoiselle ) library. For the example we are going to execute you can download the dependency using maven, based on the example below of pom.xml file:    <dependency>                 <groupId>br.gov.frameworkdemoiselle</groupId>                 <artifactId>demoi...

ENUM with NodeJS

Image
ENUMS are a type of structure which assists in the source code legibility. Instead of defining hard-code values in the source code, like “0”, null, or generic types such 0 or 1 or 2, it is possible to define friendly names with the meaning of such values, normally even related to some business vocabulary, for instance: 0=> GREEN, 1=> BLUE and 2:> RED.   Some programming languages as JAVA have reserved keywords to define enum structores. It is not the case of node.js. However, it is possible to define ENUM with Java Script / Node. using some strategies, as objects structures with constants. Here you can see one example of enum definition const RECTANGLE_DIMENSIONS = {     SMALL: [ 10 , 20 ],     MEDIUM: [ 20 , 40 ],     LARGE: [ 40 , 80 ], }; Once it is defined, we can make refence to its values using the constant names, improving de readability of the source code. Observe in the example below the enum values being used as pa...