chacha20poly1305 icon indicating copy to clipboard operation
chacha20poly1305 copied to clipboard

Are there any examples of this?

Open pogland opened this issue 8 years ago • 12 comments

I am stumped on how to use this. I really want to use ChaCha20 plus Poly1305 but it is not very popular so I couldn't find any sources on ChaCha20. This is the only source I have found. But I don't understand it very well. Could you put something like example.html in the Code area?

pogland avatar Apr 09 '16 00:04 pogland

it is designed for use with browserify, or in node.js, if you need something standalone you can use wzrd.in

calvinmetcalf avatar Apr 10 '16 02:04 calvinmetcalf

same to me, I think the package needs a demo to encode and decode a buffer.

h2y avatar Mar 19 '17 15:03 h2y

These code can't work as expected. T.T

console.log(originBuffer.toString());

cipher.setAAD(originBuffer);
let cipherRet = cipher.update(originBuffer, 'binary', 'hex');
    cipherRet += cipher.final('hex');
    
var tag = cipher.getAuthTag();
    
decipher.setAAD(originBuffer);
decipher.setAuthTag(tag);
decipher.update(cipherRet, 'hex', 'binary');
let out = decipher.final('binary');

console.log('out: ', out.toString());

h2y avatar Mar 19 '17 15:03 h2y

if you just want to know how to use buffers you can see these node references unless I'm misunderstanding

calvinmetcalf avatar Mar 20 '17 12:03 calvinmetcalf

thanks for help, I'd like to use this module like another cipher in crypto. but the useage is not same. so i don't know how to do.

h2y avatar Mar 21 '17 00:03 h2y

the usage is identical to aes-gcm, what exactly is the issue you are having?

calvinmetcalf avatar Mar 21 '17 01:03 calvinmetcalf

ok I see the error in your code, binary doesn't do what you think it does and you were listening for the wrong thing a couple places.

console.log(originBuffer.toString());

cipher.setAAD(originBuffer); // you don't really have to do this, you can, but it's usualy for data you are not planing on encrypting like meta data
let cipherRet = cipher.update(originBuffer, 'this is ignored because you gave it a buffer', 'hex');
    cipherRet += cipher.final('hex'); // this is unlikely to every give you anything because of the type of cipher but it doesn't hurt to use it
    
var tag = cipher.getAuthTag();
    
decipher.setAAD(originBuffer); // see above, you don't need to do this and if you do the plain text is not what you'd want to be using as the additional authenticated data
decipher.setAuthTag(tag);
let out = decipher.update(cipherRet, 'hex'); // get it out as a buffer
decipher.final(); // this will never return anything because it's a stream cipher

calvinmetcalf avatar Mar 21 '17 12:03 calvinmetcalf

Thank you so much for the code.I really want to use ChaCha20, but I don't understand it very well. Could you put demo to encode and decode a message in the Code area? These code can't work! help!

var chacha20 = require('./browser');

var key = new Buffer('3zTvzr3p67VC61jmV54rIYu1545x4TlY'); var nonce = new Buffer('abcdef123456'); var nonencrypteddata = "1224345";

var cipher = chacha20.createCipher(key, nonce); var decipher = chacha20.createDecipher(key, nonce);

cipher.setAAD(nonencrypteddata); var tag = cipher.getAuthTag(); decipher.setAAD(nonencrypteddata); decipher.setAuthTag(tag);

image

xflxy avatar Sep 06 '17 06:09 xflxy

you need to finish encrypting all your data (by calling final) before you can call getAuthTag, then you need to call setAAD and setAuthTag before you add any data

calvinmetcalf avatar Sep 06 '17 11:09 calvinmetcalf

Thanks, The problem is solved. @calvinmetcalf

xflxy avatar Sep 08 '17 06:09 xflxy

Hi @calvinmetcalf, can you give me an useful example with real data for encryption and decryption with ChaCha20 only, not ChaCha20 Poly1305? I think your instructions are incomplete. Thanks.

GentritMustafa avatar Oct 16 '17 14:10 GentritMustafa

@GentritMustafa there is this, do you have some questions about that?

calvinmetcalf avatar Oct 16 '17 17:10 calvinmetcalf