SlideShare a Scribd company logo
José Manuel Ortega Candel
Web Cryptography with JavaScript
The talk would aim to introduce the cryptography from the developer point of view, showing
ways to encrypt information with JavaScript in both client and server side for web applications.
The talking points could be:
 Introduction to security in web applications (authentication, authorization,
confidentiality, integrity)
 Browser storage
 Information encryption and decryption with JavaScript
 Web Cryptography API and browsers support
 Libraries let you use encryption algorithms like SHA,AES,RSA(CryptoJS, SJCL)
 Cipher information in server side with NodeJS
 Tools and plugins for browsers that allow checking the main algorithms used to encrypt
information
 JavaScript Obfuscation
 Practical application that uses any of encryption libraries discussed
Keywords: Security, Encryption, Libraries, Tools ,Obfuscation, JavaScript
Introduction to security in web applications (authentication, authorization, confidentiality,
integrity)
Cryptography
The discipline that embodies principles, means, and methods for providing information
security, including confidentiality, data integrity, nonrepudiation, and authenticity.
Browser storage
The actual state is the lack of cryptographic functions that are supported in all browsers.
The actual tendency is to use the browser localStorage and a possible attacker could use this
information to extract the contents to be keeping
With HTTPS the communication is encrypted, but suffered one MITM attack and with the right
tools like sniffers it can get to see the data.
Further, there are techniques like SSLStrip that allows to convert HTTPS traffic to HTTP
through a MITM attack.
For these reasons, it would be advisable to add another security layer with a crypto library in
JavaScript.
Comparing local storage clear text with local storage encrypted
In clear text version we can see key and value in clear in browser console
In encrypted version we can see that notes value are not in clear text.
More over, we have other keys like iv and salt variables.
Information encryption and decryption with JavaScript
Introduce to algorithms
 MD5, SHA-1,SHA-256,SHA-512 (hash functions).Allow check files integrity and
document signing
 AES [Private key cryptography][Used in WPA2]
 RSA-4096 [Public key cryptography]
 RC4[Used in SSL]
AES
The AES algorithm is a symmetric block cipher that can encrypt (encipher) and decrypt
(decipher) information.
The main features AES algorithm are:
 Shared secret key algorithm
 Symmetrical
 Same key to encrypt and decrypt
 128 192 256 bit key sizes
Any message encrypted with a public key can be decrypted with a private key and vice versa,
but an encrypted message cannot be decrypted by the same key that encrypted it as in symmetric
key encryption.
In asymmetric key cryptography, each party has two keys, a public key and a private keys
The public key is shared to the world, and the private key is kept private
The keys are generated in such a way that any message encrypted by the public key in the pair
can only be decrypted by the private key, and viceversa
It can be identified the following elements:
message = the unencrypted, readable data we care about.
cipherText = the message after encryption, the data the adversary gets to see.
Key = the secret required to encrypt and decrypt the message
Encryption: ciphertext = f(key, message)
Decryption: cleartext = f(key, cipherText)
AES algorithm JavaScript implementation
Initialization Vector (IV)
A vector used in defining the starting point of an encryption process within a
cryptographic algorithm.
RSA
The main features RSA algorithm are:
 Algorithm public / private key
 Asymmetric
 It is encrypted with the public key and decrypted with the key private
Asymmetric key cryptography works in a similar manner to symmetric key cryptography except
that the keys are generated in a special manner that allows them to decrypt only messages
encrypted by the other key in the pair
While there are many ways to do this, the most common algorithm is known as the RSA
keygen algorithm
Public key: (n, e); To encrypt: C ≡ Me (mod n)
Private key (n, d); To decrypt: M ≡ Ce (mod n)
Pub-Key Encryption (PKE)
Encrypt message(M) using public-key(pk)
Decrypt Cipher text(C) using secret-key(sk)
E(pk, M) → C
D(sk, C) → M
RSA algorithm JavaScript implementation
Web Cryptography API and browsers support
This specification describes an API for cryptographic operations like:
 Hash functions
 Public and private key algorithms
 Signature generation and data verification
 Encryption and decryption
In browser support, only Chrome, FireFox and Opera offer total support for Web Crypo
API.
In this table we can see browser support for different algorithms that offers web crypto API
Methods and algorithms supported by Web Crypto API
WebCrypto API RSA Public/Private Key
WebCrypto API Sign/Verify
WebCrypto API Encrypt/Decrypt
Libraries let you use encryption algorithms like SHA,AES,RSA(CryptoJS, SJCL)
Stanford Javascript Crypto Library(SJCL)
 It supports AES,SHA-256,HMAC,PBKDF2 algorithms
Crypto-JS
Cipher information in server side with NodeJS
 require('crypto')
 OPENSSL is required install in server
o Methods of crypto object
Testing crypto object
Tools
Mymail-Crypt for Gmail
Plugin for Chrome that allow generate our private key for encrypt messages
JavaScript Cryptography tools
Web cryptography javascript
DuckDugGo Cryptography hacks
 Identifying Hash Algorithm and Finding Plain text from Hashes
NoScript plugin for Firefox that allows protection for Cross Site Scripting(XSS)
JavaScript obfuscation
 Benefits of obfuscating JavaScript
o Protect source code
o Prevent code theft and reuse
o Protect intellectual property
o Add an extra security layer
 Online tools for code obfuscation
o https://jscrambler.com/es
o http://www.minifyjs.com/javascript-obfuscator
o http://www.javascriptobfuscator.com/Javascript-Obfuscator.aspx
Practical application that uses any of encryption libraries discussed
 Analysis of security telegram web application
 AES, SHA-1 implementation
https://code.google.com/p/crypto-js
 RSA implementation
http://www-cs-students.stanford.edu/~tjw/jsbn
We can see the implementation of aesEncrypt and aesDecrypt methods. These
methods are using the CryptoJS library
The main problem with this protocol encryption is the use of SHA-1 algorithm for
generating the message key, since SHA-1 is an algorithm cryptographically broken.
The security of this protocol is that the key is generated from the contents of the user
message.
Web cryptography javascript
References
https://www.owasp.org/index.php/Guide_to_Cryptography
http://www.w3.org/TR/WebCryptoAPI
http://www.movable-type.co.uk/scripts/aes.html
https://diafygi.github.io/webcrypto-examples
http://crypto.stanford.edu/sjcl
http://nodejs.org/api/crypto.html
http://aesencryption.net
https://telegram.org/apps#source-code

More Related Content

PDF
Encryption Deep Dive
PPTX
Secure hash function
PPT
Network security cryptographic hash function
PPTX
[Wroclaw #8] TLS all the things!
PPT
Lecture 3b public key_encryption
PDF
HMAC authentication
PPTX
HMAC - HASH FUNCTION AND DIGITAL SIGNATURES
Encryption Deep Dive
Secure hash function
Network security cryptographic hash function
[Wroclaw #8] TLS all the things!
Lecture 3b public key_encryption
HMAC authentication
HMAC - HASH FUNCTION AND DIGITAL SIGNATURES

What's hot (20)

PPTX
Cryptography - Simplified - Hash Functions
PPTX
Encryption
PDF
Searchable Encryption Systems
PPTX
Client-Side Wallets in DApps - Nakov @ BlockWorld 2018 (San Jose)
PPTX
Breaking out of crypto authentication
PPTX
Encryption
ODP
Https presentation
PDF
Sw prezen3pdf
PPTX
Toni de la Fuente - Automate or die! How to survive to an attack in the Cloud...
PPTX
SSL Primer
PDF
AREA41 - Anatomy of attacks aimed at financial sector by the Lazarus group
PDF
Sw2 prezen3pdf
PPT
DOC
RSA alogrithm
PDF
Cryptography in PHP: use cases
PDF
PPTX
Crypto Wallets: A Technical Perspective (Nakov at OpenFest 2018)
PPTX
PDF
OpenOffice.org Digital Signatures, OOoCon 2004
Cryptography - Simplified - Hash Functions
Encryption
Searchable Encryption Systems
Client-Side Wallets in DApps - Nakov @ BlockWorld 2018 (San Jose)
Breaking out of crypto authentication
Encryption
Https presentation
Sw prezen3pdf
Toni de la Fuente - Automate or die! How to survive to an attack in the Cloud...
SSL Primer
AREA41 - Anatomy of attacks aimed at financial sector by the Lazarus group
Sw2 prezen3pdf
RSA alogrithm
Cryptography in PHP: use cases
Crypto Wallets: A Technical Perspective (Nakov at OpenFest 2018)
OpenOffice.org Digital Signatures, OOoCon 2004
Ad

Similar to Web cryptography javascript (20)

PPT
Java Crypto
PPTX
PPTX
Introduction to Cryptography.pptx
PDF
The Time-Consuming Task Of Preparing A Data Set For...
PDF
Data encryption algorithm(edit)
PPTX
Basic Cryptography unit 4 CSS
PPT
Ch11 Basic Cryptography
PPTX
Encryption techniques
PPT
Secure Socket Layer (SSL)
PPT
Java Symmetric
PDF
Secure 3 kany-vanda
PPTX
Cryptography
PDF
SSL/TLS Handshake
PPTX
Practical Cryptography and Security Concepts for Developers
PPT
Security via Java
PPT
The new rocket science stuff in microsoft pki
PPTX
Crypto failures every developer should avoid
PPTX
Crypto failures every developer should avoid
PDF
Introduction to Cryptography
PDF
Caesar Cipher Method Design and Implementation Based on Java, C++, and Python...
Java Crypto
Introduction to Cryptography.pptx
The Time-Consuming Task Of Preparing A Data Set For...
Data encryption algorithm(edit)
Basic Cryptography unit 4 CSS
Ch11 Basic Cryptography
Encryption techniques
Secure Socket Layer (SSL)
Java Symmetric
Secure 3 kany-vanda
Cryptography
SSL/TLS Handshake
Practical Cryptography and Security Concepts for Developers
Security via Java
The new rocket science stuff in microsoft pki
Crypto failures every developer should avoid
Crypto failures every developer should avoid
Introduction to Cryptography
Caesar Cipher Method Design and Implementation Based on Java, C++, and Python...
Ad

More from Jose Manuel Ortega Candel (20)

PDF
Seguridad y auditorías en Modelos grandes del lenguaje (LLM)
PDF
Seguridad y auditorías en Modelos grandes del lenguaje (LLM).pdf
PDF
Beyond the hype: The reality of AI security.pdf
PDF
Seguridad de APIs en Drupal_ herramientas, mejores prácticas y estrategias pa...
PDF
Security and auditing tools in Large Language Models (LLM).pdf
PDF
Herramientas de benchmarks para evaluar el rendimiento en máquinas y aplicaci...
PDF
Asegurando tus APIs Explorando el OWASP Top 10 de Seguridad en APIs.pdf
PDF
PyGoat Analizando la seguridad en aplicaciones Django.pdf
PDF
Ciberseguridad en Blockchain y Smart Contracts: Explorando los Desafíos y Sol...
PDF
Evolution of security strategies in K8s environments- All day devops
PDF
Evolution of security strategies in K8s environments.pdf
PDF
Implementing Observability for Kubernetes.pdf
PDF
Computación distribuida usando Python
PDF
Seguridad en arquitecturas serverless y entornos cloud
PDF
Construyendo arquitecturas zero trust sobre entornos cloud
PDF
Tips and tricks for data science projects with Python
PDF
Sharing secret keys in Docker containers and K8s
PDF
Implementing cert-manager in K8s
PDF
Python para equipos de ciberseguridad(pycones)
PDF
Python para equipos de ciberseguridad
Seguridad y auditorías en Modelos grandes del lenguaje (LLM)
Seguridad y auditorías en Modelos grandes del lenguaje (LLM).pdf
Beyond the hype: The reality of AI security.pdf
Seguridad de APIs en Drupal_ herramientas, mejores prácticas y estrategias pa...
Security and auditing tools in Large Language Models (LLM).pdf
Herramientas de benchmarks para evaluar el rendimiento en máquinas y aplicaci...
Asegurando tus APIs Explorando el OWASP Top 10 de Seguridad en APIs.pdf
PyGoat Analizando la seguridad en aplicaciones Django.pdf
Ciberseguridad en Blockchain y Smart Contracts: Explorando los Desafíos y Sol...
Evolution of security strategies in K8s environments- All day devops
Evolution of security strategies in K8s environments.pdf
Implementing Observability for Kubernetes.pdf
Computación distribuida usando Python
Seguridad en arquitecturas serverless y entornos cloud
Construyendo arquitecturas zero trust sobre entornos cloud
Tips and tricks for data science projects with Python
Sharing secret keys in Docker containers and K8s
Implementing cert-manager in K8s
Python para equipos de ciberseguridad(pycones)
Python para equipos de ciberseguridad

Recently uploaded (20)

PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
cuic standard and advanced reporting.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
KodekX | Application Modernization Development
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Electronic commerce courselecture one. Pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Empathic Computing: Creating Shared Understanding
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPT
Teaching material agriculture food technology
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Programs and apps: productivity, graphics, security and other tools
cuic standard and advanced reporting.pdf
Review of recent advances in non-invasive hemoglobin estimation
Encapsulation_ Review paper, used for researhc scholars
KodekX | Application Modernization Development
Reach Out and Touch Someone: Haptics and Empathic Computing
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Digital-Transformation-Roadmap-for-Companies.pptx
The AUB Centre for AI in Media Proposal.docx
Electronic commerce courselecture one. Pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Empathic Computing: Creating Shared Understanding
20250228 LYD VKU AI Blended-Learning.pptx
Approach and Philosophy of On baking technology
Building Integrated photovoltaic BIPV_UPV.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
The Rise and Fall of 3GPP – Time for a Sabbatical?
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Teaching material agriculture food technology

Web cryptography javascript

  • 1. José Manuel Ortega Candel Web Cryptography with JavaScript The talk would aim to introduce the cryptography from the developer point of view, showing ways to encrypt information with JavaScript in both client and server side for web applications. The talking points could be:  Introduction to security in web applications (authentication, authorization, confidentiality, integrity)  Browser storage  Information encryption and decryption with JavaScript  Web Cryptography API and browsers support  Libraries let you use encryption algorithms like SHA,AES,RSA(CryptoJS, SJCL)  Cipher information in server side with NodeJS  Tools and plugins for browsers that allow checking the main algorithms used to encrypt information  JavaScript Obfuscation  Practical application that uses any of encryption libraries discussed Keywords: Security, Encryption, Libraries, Tools ,Obfuscation, JavaScript
  • 2. Introduction to security in web applications (authentication, authorization, confidentiality, integrity) Cryptography The discipline that embodies principles, means, and methods for providing information security, including confidentiality, data integrity, nonrepudiation, and authenticity. Browser storage The actual state is the lack of cryptographic functions that are supported in all browsers. The actual tendency is to use the browser localStorage and a possible attacker could use this information to extract the contents to be keeping With HTTPS the communication is encrypted, but suffered one MITM attack and with the right tools like sniffers it can get to see the data. Further, there are techniques like SSLStrip that allows to convert HTTPS traffic to HTTP through a MITM attack. For these reasons, it would be advisable to add another security layer with a crypto library in JavaScript.
  • 3. Comparing local storage clear text with local storage encrypted In clear text version we can see key and value in clear in browser console In encrypted version we can see that notes value are not in clear text. More over, we have other keys like iv and salt variables.
  • 4. Information encryption and decryption with JavaScript Introduce to algorithms  MD5, SHA-1,SHA-256,SHA-512 (hash functions).Allow check files integrity and document signing  AES [Private key cryptography][Used in WPA2]  RSA-4096 [Public key cryptography]  RC4[Used in SSL] AES The AES algorithm is a symmetric block cipher that can encrypt (encipher) and decrypt (decipher) information. The main features AES algorithm are:  Shared secret key algorithm  Symmetrical  Same key to encrypt and decrypt  128 192 256 bit key sizes Any message encrypted with a public key can be decrypted with a private key and vice versa, but an encrypted message cannot be decrypted by the same key that encrypted it as in symmetric key encryption. In asymmetric key cryptography, each party has two keys, a public key and a private keys The public key is shared to the world, and the private key is kept private The keys are generated in such a way that any message encrypted by the public key in the pair can only be decrypted by the private key, and viceversa It can be identified the following elements: message = the unencrypted, readable data we care about. cipherText = the message after encryption, the data the adversary gets to see. Key = the secret required to encrypt and decrypt the message Encryption: ciphertext = f(key, message) Decryption: cleartext = f(key, cipherText)
  • 5. AES algorithm JavaScript implementation Initialization Vector (IV) A vector used in defining the starting point of an encryption process within a cryptographic algorithm.
  • 6. RSA The main features RSA algorithm are:  Algorithm public / private key  Asymmetric  It is encrypted with the public key and decrypted with the key private Asymmetric key cryptography works in a similar manner to symmetric key cryptography except that the keys are generated in a special manner that allows them to decrypt only messages encrypted by the other key in the pair While there are many ways to do this, the most common algorithm is known as the RSA keygen algorithm Public key: (n, e); To encrypt: C ≡ Me (mod n) Private key (n, d); To decrypt: M ≡ Ce (mod n) Pub-Key Encryption (PKE) Encrypt message(M) using public-key(pk) Decrypt Cipher text(C) using secret-key(sk) E(pk, M) → C D(sk, C) → M
  • 7. RSA algorithm JavaScript implementation
  • 8. Web Cryptography API and browsers support This specification describes an API for cryptographic operations like:  Hash functions  Public and private key algorithms  Signature generation and data verification  Encryption and decryption In browser support, only Chrome, FireFox and Opera offer total support for Web Crypo API. In this table we can see browser support for different algorithms that offers web crypto API
  • 9. Methods and algorithms supported by Web Crypto API
  • 10. WebCrypto API RSA Public/Private Key
  • 13. Libraries let you use encryption algorithms like SHA,AES,RSA(CryptoJS, SJCL) Stanford Javascript Crypto Library(SJCL)  It supports AES,SHA-256,HMAC,PBKDF2 algorithms
  • 15. Cipher information in server side with NodeJS  require('crypto')  OPENSSL is required install in server o Methods of crypto object Testing crypto object
  • 16. Tools Mymail-Crypt for Gmail Plugin for Chrome that allow generate our private key for encrypt messages
  • 19. DuckDugGo Cryptography hacks  Identifying Hash Algorithm and Finding Plain text from Hashes
  • 20. NoScript plugin for Firefox that allows protection for Cross Site Scripting(XSS)
  • 21. JavaScript obfuscation  Benefits of obfuscating JavaScript o Protect source code o Prevent code theft and reuse o Protect intellectual property o Add an extra security layer  Online tools for code obfuscation o https://jscrambler.com/es o http://www.minifyjs.com/javascript-obfuscator o http://www.javascriptobfuscator.com/Javascript-Obfuscator.aspx
  • 22. Practical application that uses any of encryption libraries discussed  Analysis of security telegram web application  AES, SHA-1 implementation https://code.google.com/p/crypto-js  RSA implementation http://www-cs-students.stanford.edu/~tjw/jsbn
  • 23. We can see the implementation of aesEncrypt and aesDecrypt methods. These methods are using the CryptoJS library
  • 24. The main problem with this protocol encryption is the use of SHA-1 algorithm for generating the message key, since SHA-1 is an algorithm cryptographically broken. The security of this protocol is that the key is generated from the contents of the user message.