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('') );実行
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) );実行
messageHello, world!
codevar rsa = new Math.crypto.RSA(); var signature = rsa.setKey( input('private-key') ).sign( input('message') ); output( signature.map(hex).join('') );実行
signaturehex:
codevar rsa = new Math.crypto.RSA(); var consistent = rsa.setKey( input('public-key') ).verify( input('message'), input('signature') ); output( consistent ? 'consistent' : 'inconsistent' );実行
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 );実行