001package org.apache.commons.ssl.org.bouncycastle.asn1.x509; 002 003import java.math.BigInteger; 004import java.util.Enumeration; 005 006import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1EncodableVector; 007import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Integer; 008import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Object; 009import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Primitive; 010import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Sequence; 011import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1TaggedObject; 012import org.apache.commons.ssl.org.bouncycastle.asn1.DERSequence; 013 014/** 015 * @deprecated use org.bouncycastle.asn1.pkcs.RSAPublicKey 016 */ 017public class RSAPublicKeyStructure 018 extends ASN1Object 019{ 020 private BigInteger modulus; 021 private BigInteger publicExponent; 022 023 public static RSAPublicKeyStructure getInstance( 024 ASN1TaggedObject obj, 025 boolean explicit) 026 { 027 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 028 } 029 030 public static RSAPublicKeyStructure getInstance( 031 Object obj) 032 { 033 if(obj == null || obj instanceof RSAPublicKeyStructure) 034 { 035 return (RSAPublicKeyStructure)obj; 036 } 037 038 if(obj instanceof ASN1Sequence) 039 { 040 return new RSAPublicKeyStructure((ASN1Sequence)obj); 041 } 042 043 throw new IllegalArgumentException("Invalid RSAPublicKeyStructure: " + obj.getClass().getName()); 044 } 045 046 public RSAPublicKeyStructure( 047 BigInteger modulus, 048 BigInteger publicExponent) 049 { 050 this.modulus = modulus; 051 this.publicExponent = publicExponent; 052 } 053 054 public RSAPublicKeyStructure( 055 ASN1Sequence seq) 056 { 057 if (seq.size() != 2) 058 { 059 throw new IllegalArgumentException("Bad sequence size: " 060 + seq.size()); 061 } 062 063 Enumeration e = seq.getObjects(); 064 065 modulus = ASN1Integer.getInstance(e.nextElement()).getPositiveValue(); 066 publicExponent = ASN1Integer.getInstance(e.nextElement()).getPositiveValue(); 067 } 068 069 public BigInteger getModulus() 070 { 071 return modulus; 072 } 073 074 public BigInteger getPublicExponent() 075 { 076 return publicExponent; 077 } 078 079 /** 080 * This outputs the key in PKCS1v2 format. 081 * <pre> 082 * RSAPublicKey ::= SEQUENCE { 083 * modulus INTEGER, -- n 084 * publicExponent INTEGER, -- e 085 * } 086 * </pre> 087 * <p> 088 */ 089 public ASN1Primitive toASN1Primitive() 090 { 091 ASN1EncodableVector v = new ASN1EncodableVector(); 092 093 v.add(new ASN1Integer(getModulus())); 094 v.add(new ASN1Integer(getPublicExponent())); 095 096 return new DERSequence(v); 097 } 098}