1"use strict";(self.webpackChunkmy_website=self.webpackChunkmy_website||[]).push([["4394"],{7295(e,n,t){t.r(n),t.d(n,{metadata:()=>r,default:()=>l,frontMatter:()=>c,contentTitle:()=>s,toc:()=>p,assets:()=>o});var r=JSON.parse('{"id":"interop/java","title":"Java","description":"AES-128-CBC Decryption","source":"@site/versioned_docs/version-3.0/interop/java.md","sourceDirName":"interop","slug":"/interop/java","permalink":"/docs/3.0/interop/java","draft":false,"unlisted":false,"editUrl":"https://github.com/phpseclib/phpseclib.github.io/tree/source/versioned_docs/version-3.0/interop/java.md","tags":[],"version":"3.0","frontMatter":{"title":"Java"},"sidebar":"tutorialSidebar","previous":{"title":"Python","permalink":"/docs/3.0/interop/python"},"next":{"title":"JavaScript","permalink":"/docs/3.0/interop/javascript"}}'),a=t(4848),i=t(8453);let c={title:"Java"},s,o={},p=[{value:"AES-128-CBC Decryption",id:"aes-128-cbc-decryption",level:2},{value:"RSA Decryption",id:"rsa-decryption",level:2},{value:"RSA Signature Verification",id:"rsa-signature-verification",level:2}];function y(e){let n={a:"a",code:"code",em:"em",h2:"h2",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(n.h2,{id:"aes-128-cbc-decryption",children:"AES-128-CBC Decryption"}),"\n",(0,a.jsx)(n.p,{children:"Encrypting a string using AES-128-CBC with phpseclib:"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-php",children:"use phpseclib3\\Crypt\\AES;\n\n$cipher = new AES('cbc');\n$cipher->setKey(str_repeat('a', 16));\n$cipher->setIV(str_repeat('b', 16));\n\necho bin2hex($cipher->encrypt('test'));\n"})}),"\n",(0,a.jsx)(n.p,{children:"Decrypting that same string with Java:"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-java",children:'import javax.xml.bind.DatatypeConverter;\nimport javax.crypto.spec.SecretKeySpec;\nimport javax.crypto.spec.IvParameterSpec;\nimport javax.crypto.Cipher;\n\npublic class Test\n{\n public static void main(String[] args) throws Exception\n {\n String key = "aaaaaaaaaaaaaaaa";\n String iv = "bbbbbbbbbbbbbbbb";\n String ciphertext = "10f42fd95857ed2775cfbc4b471bc213";\n\n byte[] ciphertextBytes = DatatypeConverter.parseHexBinary(ciphertext);\n\n // perform the actual decryption\n Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");\n SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "AES");\n IvParameterSpec ivSpec = new IvParameterSpec(iv.getBytes());\n cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);\n byte[] plaintextBytes = cipher.doFinal(ciphertextBytes);\n String plaintext = new String(plaintextBytes);\n\n System.out.println(plaintext);\n }\n}\n'})}),"\n",(0,a.jsx)(n.h2,{id:"rsa-decryption",children:"RSA Decryption"}),"\n",(0,a.jsx)(n.p,{children:"Encryption with PHP:"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-php",children:"use phpseclib3\\Crypt\\PublicKeyLoader;\n\n$key = PublicKeyLoader::load('-----BEGIN RSA PUBLIC KEY-----\nMEgCQQCo9+BpMRYQ/dL3DS2CyJxRF+j6ctbT3/Qp84+KeFhnii7NT7fELilKUSnx\nS30WAvQCCo2yU1orfgqr41mM70MBAgMBAAE=\n-----END RSA PUBLIC KEY-----');\n$key = $key->withPadding(RSA::ENCRYPTION_PKCS1);\necho base64_encode($key->encrypt('test'));\n"})}),"\n",(0,a.jsx)(n.p,{children:"Decryption with Java:"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-java",children:'import org.bouncycastle.openssl.PEMParser;\nimport org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter;\nimport org.bouncycastle.openssl.PEMKeyPair;\nimport java.security.KeyPair;\nimport java.io.StringReader;\nimport javax.crypto.Cipher;\nimport java.util.Base64;\nimport java.security.interfaces.RSAPrivateKey;\n\npublic class Test\n{\n public static void main(String[] args) throws Exception\n {\n String ciphertext = "L812/9Y8TSpwErlLR6Bz4J3uR/T5YaqtTtB5jxtD1qazGPI5t15V9drWi58colGOZFeCnGKpCrtQWKk4HWRocQ==";\n\n String key = "-----BEGIN RSA PRIVATE KEY-----\\n" +\n"MIIBOgIBAAJBAKj34GkxFhD90vcNLYLInFEX6Ppy1tPf9Cnzj4p4WGeKLs1Pt8Qu\\n" +\n"KUpRKfFLfRYC9AIKjbJTWit+CqvjWYzvQwECAwEAAQJAIJLixBy2qpFoS4DSmoEm\\n" +\n"o3qGy0t6z09AIJtH+5OeRV1be+N4cDYJKffGzDa88vQENZiRm0GRq6a+HPGQMd2k\\n" +\n"TQIhAKMSvzIBnni
17ot/OSie2TmJLY4SwTQAevXysE2RbFDYdAiEBCUEaRQnMnbp7\\n" +\n"9mxDXDf6AU0cN/RPBjb9qSHDcWZHGzUCIG2Es59z8ugGrDY+pxLQnwfotadxd+Uy\\n" +\n"v/Ow5T0q5gIJAiEAyS4RaI9YG8EWx/2w0T67ZUVAw8eOMB6BIUg0Xcu+3okCIBOs\\n" +\n"/5OiPgoTdSy7bcF9IGpSE8ZgGKzgYQVZeN97YE00\\n" +\n"-----END RSA PRIVATE KEY-----\\n";\n\n // load the private key\n PEMParser pemParser = new PEMParser(new StringReader(key));\n JcaPEMKeyConverter converter = new JcaPEMKeyConverter();\n KeyPair keyPair = converter.getKeyPair((PEMKeyPair) pemParser.readObject());\n RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();\n\n // load the ciphertext\n byte[] cipherBytes = Base64.getDecoder().decode(ciphertext);\n\n // perform the actual decryption\n Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");\n cipher.init(Cipher.DECRYPT_MODE, privateKey);\n byte[] plaintextBytes = cipher.doFinal(cipherBytes);\n String plaintext = new String(plaintextBytes);\n\n System.out.println(plaintext);\n }\n}\n'})}),"\n",(0,a.jsxs)(n.p,{children:["The above code only works with PKCS1 keys. If you want to load a PKCS8 key you'll need to make the following changes (using the ",(0,a.jsx)(n.a,{href:"/docs/3.0/phpbb#actions",children:"phpBB MOD Text Template"}),"):"]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-java",children:'#\n#-----[ FIND ]------------------------------------------\n#\nimport org.bouncycastle.openssl.PEMParser;\nimport org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter;\nimport org.bouncycastle.openssl.PEMKeyPair;\nimport java.security.KeyPair;\nimport java.io.StringReader;\n#\n#-----[ REPLACE WITH ]----------------------------------\n#\nimport java.security.spec.PKCS8EncodedKeySpec;\nimport java.security.KeyFactory;\n#\n#-----[ FIND ]------------------------------------------\n#\n String key = "-----BEGIN RSA PRIVATE KEY-----\\n" +\n"MIIBOgIBAAJBAKj34GkxFhD90vcNLYLInFEX6Ppy1tPf9Cnzj4p4WGeKLs1Pt8Qu\\n" +\n"KUpRKfFLfRYC9AIKjbJTWit+CqvjWYzvQwECAwEAAQJAIJLixBy2qpFoS4DSmoEm\\n" +\n"o3qGy0t6z09AIJtH+5OeRV1be+N4cDYJKffGzDa88vQENZiRm0GRq6a+HPGQMd2k\\n" +\n"TQIhAKMSvzIBnni
17ot/OSie2TmJLY4SwTQAevXysE2RbFDYdAiEBCUEaRQnMnbp7\\n" +\n"9mxDXDf6AU0cN/RPBjb9qSHDcWZHGzUCIG2Es59z8ugGrDY+pxLQnwfotadxd+Uy\\n" +\n"v/Ow5T0q5gIJAiEAyS4RaI9YG8EWx/2w0T67ZUVAw8eOMB6BIUg0Xcu+3okCIBOs\\n" +\n"/5OiPgoTdSy7bcF9IGpSE8ZgGKzgYQVZeN97YE00\\n" +\n"-----END RSA PRIVATE KEY-----\\n";\n\n // load the private key\n PEMParser pemParser = new PEMParser(new StringReader(key));\n JcaPEMKeyConverter converter = new JcaPEMKeyConverter();\n KeyPair keyPair = converter.getKeyPair((PEMKeyPair) pemParser.readObject());\n RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();\n#\n#-----[ REPLACE WITH ]----------------------------------\n#\n String key = "-----BEGIN PRIVATE KEY-----\\n" +\n"MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqPfgaTEWEP3S9w0t\\n" +\n"gsicURfo+nLW09/0KfOPinhYZ4ouzU+3xC4pSlEp8Ut9FgL0AgqNslNaK34Kq+NZ\\n" +\n"jO9DAQIDAQABAkAgkuLEHLaqkWhLgNKagSajeobLS3rPT0Agm0f7k55FXVt743hw\\n" +\n"Ngkp98bMNrzy9AQ1mJGbQZGrpr4c8ZAx3aRNAiEAoxK/MgGeeLui385KJ7ZOYktj\\n" +\n"hLBNAB69fKwTZFsUNh0CIQEJQRpFCcydunv2bENcN/oBTRw39E8GNv2pIcNxZkcb\\n" +\n"NQIgbYSzn3Py6AasNj6nEtCfB+i1p3F35TK/87DlPSrmAgkCIQDJLhFoj1gbwRbH\\n" +\n"/bDRPrtlRUDDx44wHoEhSDRdy77eiQIgE6z/k6I+ChN1LLttwX0galITxmAYrOBh\\n" +\n"BVl433tgTTQ=\\n" +\n"-----END PRIVATE KEY-----";\n\n // extract BER from PEM\n key = key\n .replaceAll("-+[^-]+-+", "")\n .replace("\\n", "")\n .replace("\\r", "");\n byte[] keyBytes = Base64.getDecoder().decode(key);\n\n // load decoded private key\n PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes);\n KeyFactory kf = KeyFactory.getInstance("RSA");\n RSAPrivateKey privateKey = (RSAPrivateKey) kf.generatePrivate(spec);\n'})}),"\n",(0,a.jsx)(n.p,{children:"In the PKCS1 example BouncyCastle is being used to read the key and the actual decryption is being performed by the com.sun.crypto.provider.SunJCE provider."}),"\n",(0,a.jsx)(n.p,{children:"Normally, com.sun.crypto.provider.SunJCE and org.bouncycastle.jce.provider.BouncyCastleProvider will yield the same result but that is not always the case. Consider OAEP."}),"\n",(0,a.jsx)(n.p,{children:"Here's the phpseclib code to encrypt something with OAEP:"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-php",children:"use phpseclib3\\Crypt\\PublicKeyLoader;\n\n$key = PublicKeyLoader::load('-----BEGIN RSA PUBLIC KEY-----\nMEgCQQCo9+BpMRYQ/dL3DS2CyJxRF+j6ctbT3/Qp84+KeFhnii7NT7fELilKUSnx\nS30WAvQCCo2yU1orfgqr41mM70MBAgMBAAE=\n-----END RSA PUBLIC KEY-----');\n$key = $key\n //->withPadding(RSA::ENCRYPTION_OAEP)\n ->withHash('md5')\n ->withMGFHash('sha1');\necho base64_encode($key->encrypt('test'));\n"})}),"\n",(0,a.jsx)("sup",{children:(0,a.jsxs)(n.em,{children:["(md5 is being used because the key is a 512-bit key from ",(0,a.jsx)(n.a,{href:"/docs/3.0/publickeys/rsa-keys",children:"Sample RSA Keys"}),"; 512-bits is used for brevity but because it's 512-bits sha256 can't be used per the max size formulas discussed at ",(0,a.jsx)(n.a,{href:"/docs/3.0/publickeys/rsa#rsaencryption_oaep",children:"RSA::ENCRYPTION_OAEP"}),"; sha1 would work but for the purposes of this demonstration it can't be sha1)"]})}),"\n",(0,a.jsx)(n.p,{children:"Now let's modify the Java code again:"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-java",children:'#\n#-----[ FIND ]------------------------------------------\n#\n String ciphertext = "L812/9Y8TSpwErlLR6Bz4J3uR/T5YaqtTtB5jxtD1qazGPI5t15V9drWi58colGOZFeCnGKpCrtQWKk4HWRocQ==";\n#\n#-----[ REPLACE WITH ]----------------------------------\n#\n String ciphertext = "h3j3zLT2jXCaZuwF7cgUE/Zmc/5IsIfKbaTiBhpCJo86AiyuoA3Yvni+Lrm5wu2OGv2h5R7Zu3voFcHugiystw==";\n#\n#-----[ FIND ]------------------------------------------\n#\n Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");\n#\n#-----[ REPLACE WITH ]----------------------------------\n#\n Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithMD5AndMGF1Padding");\n'})}),"\n",(0,a.jsxs)(n.p,{children:["That works just fine. BUT what if use ",(0,a.jsx)(n.code,{children:'Cipher.getInstance("RSA/ECB/OAEPWithMD5AndMGF1Padding", "BC")'})," instead? eg. what if we force org.bouncycastle.jce.provider.BouncyCastleProvider to be the crypto provider instead of com.sun.crypto.provider.SunJCE? Then it doesn't work."]}),"\n",(0,a.jsx)(n.p,{children:"org.bouncycastle.jce.provider.BouncyCastleProvider assumes the MGFHash and the Hash are using the same algorithm whereas com.sun.crypto.provider.SunJCE has the MGFHash hard-coded as sha1. To work around this we can do the following:"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-java",children:'#\n#-----[ FIND ]------------------------------------------\n#\nimport java.security.interfaces.RSAPrivateKey;\n#\n#-----[ AFTER, ADD ]------------------------------------\n#\nimport javax.crypto.spec.OAEPParameterSpec;\nimport java.security.spec.MGF1ParameterSpec;\nimport javax.crypto.spec.PSource.PSpecified;\n#\n#-----[ FIND ]------------------------------------------\n#\n Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");\n cipher.init(Cipher.DECRYPT_MODE, privateKey);\n#\n#-----[ REPLACE WITH ]----------------------------------\n#\n Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPPadding");\n OAEPParameterSpec oaepParams = new OAEPParameterSpec(\n "MD5",\n "MGF1",\n new MGF1ParameterSpec("SHA-1"),\n PSpecified.DEFAULT\n );\n cipher.init(Cipher.DECRYPT_MODE, privateKey, oaepParams);\n'})}),"\n",(0,a.jsx)(n.h2,{id:"rsa-signature-verification",children:"RSA Signature Verification"}),"\n",(0,a.jsx)(n.p,{children:"Signature creation with PHP:"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-php",children:"use phpseclib3\\Crypt\\PublicKeyLoader;\n\n$key = PublicKeyLoader::load('-----BEGIN RSA PRIVATE KEY-----\nMIIBOgIBAAJBAKj34GkxFhD90vcNLYLInFEX6Ppy1tPf9Cnzj4p4WGeKLs1Pt8Qu\nKUpRKfFLfRYC9AIKjbJTWit+CqvjWYzvQwECAwEAAQJAIJLixBy2qpFoS4DSmoEm\no3qGy0t6z09AIJtH+5OeRV1be+N4cDYJKffGzDa88vQENZiRm0GRq6a+HPGQMd2k\nTQIhAKMSvzIBnni
17ot/OSie2TmJLY4SwTQAevXysE2RbFDYdAiEBCUEaRQnMnbp7\n9mxDXDf6AU0cN/RPBjb9qSHDcWZHGzUCIG2Es59z8ugGrDY+pxLQnwfotadxd+Uy\nv/Ow5T0q5gIJAiEAyS4RaI9YG8EWx/2w0T67ZUVAw8eOMB6BIUg0Xcu+3okCIBOs\n/5OiPgoTdSy7bcF9IGpSE8ZgGKzgYQVZeN97YE00\n-----END RSA PRIVATE KEY-----')\n //->withHash('sha256')\n ->withPadding(RSA::SIGNATURE_PKCS1);\n\necho base64_encode($key->sign('zzz'));\n"})}),"\n",(0,a.jsx)(n.p,{children:"Signature verification with Java:"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-java",children:'import org.bouncycastle.openssl.PEMParser;\nimport org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter;\nimport org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;\nimport java.io.StringReader;\nimport java.util.Base64;\nimport java.security.interfaces.RSAPublicKey;\nimport java.security.Signature;\n\npublic class Test\n{\n public static void main(String[] args) throws Exception\n {\n String plaintext = "zzz";\n String signature = "MUE536c4UJSAmycs7V6qFaLMATrKMQA8TYj5xX1+fwHINz3/BafgaRt0ycoD5IxTxaclLWavrGSza4xSBHraEw==";\n\n String key = "-----BEGIN RSA PUBLIC KEY-----\\n" +\n"MEgCQQCo9+BpMRYQ/dL3DS2CyJxRF+j6ctbT3/Qp84+KeFhnii7NT7fELilKUSnx\\n" +\n"S30WAvQCCo2yU1orfgqr41mM70MBAgMBAAE=\\n" +\n"-----END RSA PUBLIC KEY-----\\n";\n\n // load the public key\n PEMParser pemParser = new PEMParser(new StringReader(key));\n JcaPEMKeyConverter converter = new JcaPEMKeyConverter();\n SubjectPublicKeyInfo pub = SubjectPublicKeyInfo.getInstance(pemParser.readObject());\n RSAPublicKey publicKey = (RSAPublicKey) converter.getPublicKey(pub);\n\n // load the plaintext\n byte[] signatureBytes = Base64.getDecoder().decode(signature);\n\n // perform the actual signature verification\n Signature sig = Signature.getInstance("SHA256withRSA");\n sig.initVerify(publicKey);\n sig.update(plaintext.getBytes());\n System.out.println(sig.verify(signatureBytes) ? "good" : "bad");\n }\n}\n'})}),"\n",(0,a.jsxs)(n.p,{children:["The above code only works with PKCS1 keys. If you want to load a PKCS8 key you'll need to make the following changes (using the ",(0,a.jsx)(n.a,{href:"/docs/3.0/phpbb#actions",children:"phpBB MOD Text Template"}),"):"]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-java",children:'#\n#-----[ FIND ]------------------------------------------\n#\nimport org.bouncycastle.openssl.PEMParser;\nimport org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter;\nimport org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;\nimport java.io.StringReader;\n#\n#-----[ REPLACE WITH ]----------------------------------\n#\nimport java.security.spec.X509EncodedKeySpec;\nimport java.security.KeyFactory;\n#\n#-----[ FIND ]------------------------------------------\n#\n String key = "-----BEGIN RSA PUBLIC KEY-----\\n" +\n"MEgCQQCo9+BpMRYQ/dL3DS2CyJxRF+j6ctbT3/Qp84+KeFhnii7NT7fELilKUSnx\\n" +\n"S30WAvQCCo2yU1orfgqr41mM70MBAgMBAAE=\\n" +\n"-----END RSA PUBLIC KEY-----\\n";\n\n // load the public key\n PEMParser pemParser = new PEMParser(new StringReader(key));\n JcaPEMKeyConverter converter = new JcaPEMKeyConverter();\n SubjectPublicKeyInfo pub = SubjectPublicKeyInfo.getInstance(pemParser.readObject());\n RSAPublicKey publicKey = (RSAPublicKey) converter.getPublicKey(pub);\n#\n#-----[ REPLACE WITH ]----------------------------------\n#\n String key = "-----BEGIN PUBLIC KEY-----\\n" +\n"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKj34GkxFhD90vcNLYLInFEX6Ppy1tPf\\n" +\n"9Cnzj4p4WGeKLs1Pt8QuKUpRKfFLfRYC9AIKjbJTWit+CqvjWYzvQwECAwEAAQ==\\n" +\n"-----END PUBLIC KEY-----";\n\n // extract BER from PEM\n key = key\n .replaceAll("-+[^-]+-+", "")\n .replace("\\n", "")\n .replace("\\r", "");\n byte[] keyBytes = Base64.getDecoder().decode(key);\n\n // load decoded public key\n X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);\n KeyFactory kf = KeyFactory.getInstance("RSA");\n RSAPublicKey publicKey = (RSAPublicKey) kf.generatePublic(spec);\n'})}),"\n",(0,a.jsxs)(n.p,{children:["If you want to do PSS signature verification and you have org.bouncycastle.jce.provider.BouncyCastleProvider as an available crypto provider (as of Java 8, sun.security.rsa.SunRsaSign does not support PSS), you can do ",(0,a.jsx)(n.code,{children:'Signature.getInstance("SHA1withRSA/PSS")'})," instead of ",(0,a.jsx)(n.code,{children:'Signature.getInstance("SHA1withRSA")'}),". If you do ",(0,a.jsx)(n.code,{children:"SHA256withRSA/PSS"})," (which you're not going to be able to do with 512-bit RSA keys) you'll need to keep in mind that the MGFHash is assumed to be the same as the regular Hash. If that's not the case (or if you're using a salt length other than the length of the Hash) then you'll need to do something like this:"]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-java",children:'#\n#-----[ FIND ]------------------------------------------\n#\nimport java.security.Signature;\n#\n#-----[ AFTER, ADD ]------------------------------------\n#\nimport java.security.spec.PSSParameterSpec;\nimport java.security.spec.MGF1ParameterSpec;\nimport java.security.MessageDigest;\n#\n#-----[ FIND ]------------------------------------------\n#\n Signature sig = Signature.getInstance("SHA256withRSA");\n#\n#-----[ REPLACE WITH ]----------------------------------\n#\n Signature sig = Signature.getInstance("RSASSA-PSS");\n PSSParameterSpec pssParams = new PSSParameterSpec(\n "SHA
1-256",\n "MGF1",\n new MGF1ParameterSpec("SHA-1"),\n MessageDigest.getInstance("SHA-256").getDigestLength(),\n PSSParameterSpec.TRAILER_FIELD_BC\n );\n sig.setParameter(pssParams);\n'})}),"\n",(0,a.jsxs)(n.p,{children:["In this example SHA-256 is the Hash, SHA-1 is the MGFHash and the salt length is equal to the length of the hash in bytes ",(0,a.jsx)(n.em,{children:"(this example requires a minimum 528-bit RSA private key instead of the 512-bit RSA private keys we've been using so a complete working example is not provided; in theory we could use MD5 as the Hash as we did with the OAEP example but Java doesn't support MD5 for PSS)"})]})]})}function l(e={}){let{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,a.jsx)(n,{...e,children:(0,a.jsx)(y,{...e})}):y(e)}},8453(e,n,t){t.d(n,{R:()=>c,x:()=>s});var r=t(6540);let a={},i=r.createContext(a);function c(e){let n=r.useContext(i);return r.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function s(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:c(e.components),r.createElement(i.Provider,{value:n},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.