public key-----BEGIN PUBLIC KEY----- MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAL+3f2PCiaHSEJNvA+/1deoeLdeLzIbl 8AQmJp0gnjWwXT31m1OmPJjJgpAYjdBM5H0y7LruGB6IKx4XkmSEa7sCAwEAAQ== -----END PUBLIC KEY-----
plaintextHello, world!
codevar rsa = new Math.crypto.RSA(); var ciphertext = rsa.setKey( input('public-key') ).encrypt( input('plaintext') ); output( ciphertext.map(hex).join('') );Run
output
private key-----BEGIN RSA PRIVATE KEY----- MIIBOgIBAAJBAL+3f2PCiaHSEJNvA+/1deoeLdeLzIbl8AQmJp0gnjWwXT31m1Om PJjJgpAYjdBM5H0y7LruGB6IKx4XkmSEa7sCAwEAAQJAWI4qCaqSaGzfuzpMV0rK bJoEEsxAbQ9JDqGQtIOckK9ZfBanZUI4I9+soR4d2XEfG9kBO2OWVsICkTdxKDWk AQIhAOhxHzJWMKueDpp0YZvGHEW5egpJ0tOS5dFr81WI5h6jAiEA0yW7lwdj/5vQ aol+IB2MJoCtRdrgH8o15BZRrj9qyAkCIADQ1NEyaD1R8q8sFWOckGDWQ81hcPH5 JAFWJaZ5MoWNAiEAl/gjcQs3tOQveE5nQbQiiB+7Fnj3MMo4SWaq+U/ZigkCIFzl lS8FUT+Pqsy57C88sorka/FUFcGctiXf4bR7xBLy -----END RSA PRIVATE KEY-----
ciphertexthex:
codevar rsa = new Math.crypto.RSA(); var plaintext = rsa.setKey( input('private-key') ).decrypt( input('ciphertext') ); output( String.fromByteArray(plaintext) );Run
messageHello, world!
codevar rsa = new Math.crypto.RSA(); var signature = rsa.setKey( input('private-key') ).sign( input('message') ); output( signature.map(hex).join('') );Run
signaturehex:
codevar rsa = new Math.crypto.RSA(); var consistent = rsa.setKey( input('public-key') ).verify( input('message'), input('signature') ); output( consistent ? 'consistent' : 'inconsistent' );Run
codevar rsa = new Math.crypto.RSA(); var key = rsa.generate(32, 65537).getKey('private', 'object'); output( "n:", key.n ); output( "e:", key.e ); output( "d:", key.d ); output( "p:", key.p ); output( "q:", key.q );Run