Issue 805:don't reopen oauth package in core

This commit is contained in:
Adrian Cole 2012-01-07 11:50:42 -08:00
parent a238efb786
commit 0b41e74728
2 changed files with 9 additions and 38 deletions

View File

@ -42,11 +42,11 @@ import org.jclouds.javax.annotation.Nullable;
import net.oauth.signature.pem.PEMReader; import net.oauth.signature.pem.PEMReader;
import net.oauth.signature.pem.PKCS1EncodedKeySpec; import net.oauth.signature.pem.PKCS1EncodedKeySpec;
import net.oauth.signature.pem.PKCS1EncodedPublicKeySpec;
import org.bouncycastle.asn1.ASN1OutputStream; import org.bouncycastle.asn1.ASN1OutputStream;
import org.bouncycastle.asn1.pkcs.RSAPrivateKeyStructure; import org.bouncycastle.asn1.pkcs.RSAPrivateKeyStructure;
import org.jclouds.crypto.Pems.PemProcessor.ResultParser; import org.jclouds.crypto.Pems.PemProcessor.ResultParser;
import org.jclouds.crypto.pem.PKCS1EncodedPublicKeySpec;
import org.jclouds.io.InputSuppliers; import org.jclouds.io.InputSuppliers;
import com.google.common.annotations.Beta; import com.google.common.annotations.Beta;

View File

@ -41,15 +41,15 @@
* *
****************************************************************************/ ****************************************************************************/
package net.oauth.signature.pem; package org.jclouds.crypto.pem;
import java.io.IOException; import java.io.IOException;
import java.math.BigInteger;
import java.security.spec.RSAPublicKeySpec; import java.security.spec.RSAPublicKeySpec;
import net.oauth.signature.pem.PKCS1EncodedKeySpec;
/** /**
* PKCS#1 encoded public key spec. In oauth package as they made all classes * PKCS#1 encoded public key spec.
* package visible.
* *
* *
* @author Adrian Cole * @author Adrian Cole
@ -79,41 +79,12 @@ public class PKCS1EncodedPublicKeySpec {
} }
/** /**
* Decode PKCS#1 encoded private key into RSAPublicKeySpec. * get the modulus and public exponent by reusing {@link PKCS1EncodedKeySpec}
*
* <p/>
* The ASN.1 syntax for the private key with CRT is
*
* <pre>
* --
* -- Representation of RSA private key with information for the CRT algorithm.
* --
* RSAPrivateKey ::= SEQUENCE {
* version Version,
* modulus INTEGER, -- n
* publicExponent INTEGER, -- e
* }
* </pre>
*
* @param keyBytes
* PKCS#1 encoded key
* @throws IOException
*/ */
private void decode(byte[] keyBytes) throws IOException { private void decode(byte[] keyBytes) throws IOException {
PKCS1EncodedKeySpec privateSpec = new PKCS1EncodedKeySpec(keyBytes);
DerParser parser = new DerParser(keyBytes); keySpec = new RSAPublicKeySpec(privateSpec.getKeySpec().getModulus(), privateSpec.getKeySpec()
.getPublicExponent());
Asn1Object sequence = parser.read();
if (sequence.getType() != DerParser.SEQUENCE)
throw new IOException("Invalid DER: not a sequence"); //$NON-NLS-1$
// Parse inside the sequence
parser = sequence.getParser();
BigInteger modulus = parser.read().getInteger();
BigInteger publicExp = parser.read().getInteger();
keySpec = new RSAPublicKeySpec(modulus, publicExp);
} }
} }